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?

Related posts

Leave a Reply

3 comments

  1. 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()