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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0