<?php
//Insert ads after second paragraph of single post content.
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
$ad_code = '<div>Ads code goes here</div>';
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $ad_code, 2, $content );
}
return $content;
}
Hi, how to repace
<?php
$a1 = get_field('fa1', 'option');
if ($a1) : ?>
<a href="<?php echo $a1['a1-l']; ?>" target="_blank" rel="nofollow"><img src="<?php echo esc_url( $a1['a1-b']['url'] ); ?>"></a>
<?php endif; ?>
instead of <div>Ads code goes here</div> in functions.php WordPress?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Perhaps this is what you mean?
<?php
//Insert ads after second paragraph of single post content.
add_filter( 'the_content', 'prefix_insert_post_ads' );
function prefix_insert_post_ads( $content ) {
$ad_code = '<div>'.sewp_381661_get_advert().'</div>';
if ( is_single() && ! is_admin() ) {
return prefix_insert_after_paragraph( $ad_code, 2, $content );
}
return $content;
}
// function to return ad markup / logic ##
function sewp_381661_get_advert(){
$a1 = get_field('fa1', 'option');
$string = ''; // define return var ##
if ($a1) {
$string = '<a href="'.$a1['a1-l'].'" target="_blank" rel="nofollow"><img src="'.esc_url( $a1['a1-b']['url'] ).'"></a>';
}
// return string for echo ##
return $string;
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0