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

I want to edit the default function the_content(). I know i can add_filter('the_content', 'with_my_function') but im having trouble outputting the old content with mine.

Heres an example of what im doing.

add_filter('the_content', 'my_function');
function my_function()
    $write = 'hello world';
    $content = apply_filters('the_content', get_the_content());
    echo $write.$content;

How can i get this to work?

share|improve this question
up vote 8 down vote accepted

Not exactly sure what you are trying to accomplish, but it looks like you are trying to prepend something to the beginning of the_content.

Try this:

add_filter('the_content', 'se24265_my_function');
function se24265_my_function( $content )
    $write = 'hello world';
    $new_content = $write . $content;
    return $new_content;

Most filters will provide a parameter or two for your function to manipulate and then return.

share|improve this answer
Ahh thats right! Of course, i need to add the variable in the functions parameters. Thanks a lot, perfect. And im doing some preg_replace() throughout the content, i just needed help getting the content! ;) – cnotethegr8 Jul 28 '11 at 4:41

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.