Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Add a sponsor block after more tag in single.php WordPress


I am looking to add a sponsor block after the more tag in the single.php.

I want it to be site wide - I don't want to put something in every post - I want to change it via theme - it will most likely be a placement.

Is this even possible?

you can view the theme I am working on

You will see the sponsor block - I want to move that down, so it sits after the first paragraph or two.

Here is the basic code for the area...

<div class="post_ad">
<a href="#">
<img src="" alt="Post Ad" width="468" height="60" align="middle" class="ad_468"/>

<div class="entry-content">

<div class="entry-image">
<?php the_content() ?>

Answers (5)


Utkarsh Kukreti answers:

add_filter('the_content', 'insert_ads_in_content');

function insert_ads_in_content($content)
if(!is_single()) return $content;
$ad = <<<EOT
<div class="ad">
<!-- ad content -->
$after = 2; // after which paragraph?

$ps = explode('</p>', $content);
$o = '';
for($i = 0; $i < count($ps); $i++)
if($after == $i) $o .= $ad;
$o .= $ps[$i] . '</p>';
return $o;

Chad Mueller comments:

Utkarsh - that works great - one concern

It shows up on every page - I just want to show up in single.php

Utkarsh Kukreti comments:



Darrin Boutote answers:

Do you want it actually in the post? Or after the post?

Chad Mueller comments:

I want it in the post - not before or after - within the post


Matt K answers:

Hi Chad,

I think putting the ad code after <?php the_content() ?> should do it, unless it's more complicated than that?

Chad Mueller comments:

no it's more complicated then that - that would just put it after the content - which i don't want...


Oleg Butuzov answers:

Hi Chad. try this. (insert it to the functions.php of your theme)
add_filter('the_content', 'adds_block');

function adds_block($content){

if (!is_single()) return $content;

return str_replace('<!--more-->', ads(), $content);


function ads(){
return 'banner code';


Monster Coder answers:

Write these codes in the functions.php in theme directory:

$sponsor_texts = 'THIS IS SPONSORED TEXT';
function sponsors_link($content){
global $sponsor_texts;
return str_replace(array('<span id="more-'.get_the_ID().'"></span>','<!--more-->'),array($sponsor_texts,$sponsor_texts),$content);

Change $sponsor_texts variable to put your sponsor codes

Monster Coder comments:

The code of Utkarsh Kukreti seems fine! But it will always add sponsor after 2nd paragraph, not after more tag! more tag may not be always after 2nd paragraph!

Note: I have tested my code with Twenty Ten theme! On other theme, need to check what <!--more--> is replaced with! we need to search and replace that only!

Chad Mueller comments:

I put this in - but I was unable to see any results.....

I understand what you are saying - it would be more dynamic if it went after the more tag - but after the first paragraph is ok as well - so it doesn't cut any content in half -