0
<?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?

3
  • Hi, how to repace <?php echo get_template_directory_uri() ?> instead of <div>Ads code goes here</div> in functions.php Wordpress? - can you explain what you want to do and perhaps why?
    – Q Studio
    Jan 17, 2021 at 17:38
  • Short codes call functions. Meaning, if you edit the theme template, you don't need shortcodes, you can use the actual function the shortcode would call..
    – Q Studio
    Jan 17, 2021 at 17:42
  • @QStudio tnx, I edited the question
    – och
    Jan 17, 2021 at 17:46

1 Answer 1

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;

}
1
  • Yeh, it's not totally clear the requirement or purpose, but best guessing as best as I can guess..
    – Q Studio
    Jan 17, 2021 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.