• I want to insert two AdSense Ads inside the post, one after the first "</p>" tag and second after the first "ol" tag.

    I’m currently using this piece of code:

    <?php
    $paragraphAfter= 1; //shows the ad after paragraph 1
    $content = apply_filters('the_content', get_the_content());
    $content = explode("</p>", $content);
    for ($i = 0; $i <count($content); $i++) {
    if ($i == $paragraphAfter) { ?>
    <!-- START OF AD CODE -->
    AdSense Code
    <!-- END OF AD CODE -->
    <?php
    }
    echo $content[$i] . "</p>";
    } ?>

    It perfectly injects Ad after the first paragraph. But how to make it do so exactly for the “ol” tag too.

    I’ve already made my noob attempts and I failed so awfully ??

    So please, it’d be great if any of you could help.

    Thanks.

Viewing 1 replies (of 1 total)
  • Something like this would work:

    <?php
    $orderedListAfter= 1;
    $content = apply_filters('the_content', get_the_content());
    $content = explode("</ol>", $content);
    for ($i = 0; $i <count($content); $i++) {
    if ($i == $orderedListAfter) { ?>
    <!-- START OF AD CODE -->
    AdSense Code
    <!-- END OF AD CODE -->
    <?php
    }
    echo $content[$i] . "</ol>";
    } ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Insert Ad after the first paragraph and "ol" tag inside post.’ is closed to new replies.