WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The Question::: This is a strange question but I need to add content to content() in page.php. How do I do this?

The Why::: You see there's a plugin that uses the [plugin id="1337"] and I am linking this id with user ID so the ID needs to be dynamic and then added to the content of the page. This way each user will see something different from the plugin it will be cool I swear.

I tried added it directly to the html but no luck it has to be added to content() somehow. No luck finding anything online either.

Installation::: I'm running wordpress version 3.2.1 and using the TwentyEleven Theme

share|improve this question
up vote 2 down vote accepted
// Hook into the_content filter here
function append_to_the_content($content){
    // Start doing stuff here ...

    // End doing stuff here ...
    $new_content = ob_get_clean();
    return $content.$new_content; // Append new content
    return $new_content.$content; // Prepend new content
} // function append_to_the_content($content)
// 11 priority avoid wpautop() that messes custom HTML
add_filter('the_content', 'append_to_the_content', 11);


share|improve this answer
Great! I appericiate your help. I'm getting an unexpected T_FUNCTION @ add_filter() line. Do I still need content before this or is your code replacing it? Because with it there or not it still gets that syntax error. For what it's worth I'm using 2011theme – Howdy_McGee Oct 25 '11 at 20:30
I used PHP 5.3 Anonymous functions. If you run 5.2, use the new version. I updated the code. – EarnestoDev Oct 25 '11 at 20:32
Ok cool, syntax errors are gone. I'm echo(ing) out my values between the ob_start() and $new_content and it shows my page just fine, but without content. I do need to echo right? – Howdy_McGee Oct 25 '11 at 20:37
OH GOD! You never remove the the_content(). NEVER! Listen: you leave the the_content() call where it is in the page.php (or whatever) code and go to your functions.php and paste my code on top of everything, right under the <?php tag! DO IT! Just do it :) The code I gave you here alters the the_content() output. But the_content() still needs to be called in your theme. TRY IT (then rate my answer and efforts)! ;) – EarnestoDev Oct 26 '11 at 3:04
Ohhh man that was my problem, missing content call. See what I'm doing with this content change is I have some protected pages and when logged in members get to see their gallery. The problem is that it shows All galleries not member specific. So now I'm going to compare userID with galleryID and make 1 univeral page that will place content based off of that. So I needed a dynamic gallery ID, but the plugin requires it to be put in the page content like [plugin id='1']. In theory it sounds good so I'm running with it. Thanks for all your help! I appreciate it greatly. Cant upvote enough – Howdy_McGee Oct 27 '11 at 16:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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