How to Add Ads after Read More Tag in WordPress


Today, this site finally reaches a new milestone, 500+ page views/day. Even though it’s very low, I decided to add ads in this blog.

This blog uses full content in archive, and I’m breaking long content using manual “read more tag” (not using excerpt).

Note: You can add more tag using the editor toolbar or using <!--more--> in text editor.

I want to add the Ads in all blog post after read more tag, so technically when visitor click the read more, they will see ads on the top of the page.

It’s tricky because when we use the_content filter, WordPress already transform <!--more--> tag into HTML tag, something like <span id="more-1325"></span>. Here’s the code:

I found the code on stack overflow:

/* Filter content */
add_filter( 'the_content', 'my_content_ads' );

 * Add Ads in Content
function my_content_ads( $content ){

    /* Not post, return. */
    if( !is_singular( 'post' ) ){
        return $content;

    /* Ads Code */
    $ads_code = '';

     * Add ads after more tag.
     * @link
    $content = preg_replace('/<span id\=\"(more\-\d+)"><\/span>/', '<span id="\1"></span>'."\n\n". $ads_code ."\n\n", $content );

    return $content;

You need to simply change the $ads_code var with your ads code.

Leave a Reply

Your email address will not be published. Required fields are marked *