CyberJunkie
CyberJunkie

Reputation: 22684

Wordpress add filter to the_content()

I'm trying to add a code to the_content() function. I tried the following

function add_something($content) {
    echo "test";
}
add_filter( 'the_content', 'add_something', 6); 

After adding the filter my posts return just the echo test without the content. How can I execute my custom code without omitting the content?

Upvotes: 5

Views: 27792

Answers (3)

NoriAmos
NoriAmos

Reputation: 1

Use this (the_content filter needs 1 parameter)

add_filter( 'the_content', 'add_something', 1);

Upvotes: 0

mario
mario

Reputation: 145512

I would surmise you need something like that (if it's indeed a filter callback):

function add_something($content) {
    return "test" . $content;
}

Seems what the docs say: http://wordpress.org/support/topic/add-something-to-the_content

Upvotes: 14

Friso Kluitenberg
Friso Kluitenberg

Reputation: 1179

you omitted the return statement.

function add_something($content) {
echo "test";
... change $content ......
return $content;

}

Be advised that if you want to modify the content, you must append it to the variable. Using echo will output 'test' at the time the script is called. It will not append or prepend it to the_content()

Upvotes: 8

Related Questions