WordPress.org

Ready to get started?Download WordPress

Forums

Insert ad or image after first paragraph (1 post)

  1. cableghost
    Member
    Posted 2 years ago #

    I'm using the below code to insert ads/images after 1 paragraph. It functions properly, however, the 'Next Page' functionality stops working.

    Is it somehow possible to add 'wp_link_pages' somewhere within?

    Any guidance would be appreciated, thank you.

    <?php
    $show_after_p = 1;
    $content = apply_filters('the_content', $post->post_content);
    if(substr_count($content, '<p>') > $show_after_p)
    {
    	$contents = explode("</p>", $content);
    	$p_count = 1;
    	foreach($contents as $content)
    	{
    		echo $content;
    
    		if($p_count == $show_after_p)
    		{
    		?>
    AD CODE
    		<?
    		}
    		echo "</p>";
    		$p_count++;
    	}
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic