Yoast SEO Calling content filters 2 additional times

I was trying to add a content filter and i discovered that the filter was being called 3 times in total. I tried slowly deleting all of the plugins and eventually found that it was Yoast that was causing this. This is absolutely insane. This means that ever single content filter gets called 3 times every single time? The performance issues alone are seriously bad. Any idea what is causing this to happen. Surely this plugin would not be released if it was calling the content 2 times.

For example. This hook will display one in the content (it does this without the plugin installed) and 2 more times at the top of the page when Yoast SEO is installed.

add_action( 'the_content', 'outputsomething');
function outputsomething() 
{
    echo "test";
}

3 Answers
3

The core of your problem is that the_content is a filter not an action, and it is supposed to return values, not echo them.

As for the “called number of times” part of the question, yes any hook can be called unlimited number of time. If you find that you need to return one result on the first call and different on the others it is a sign that you are doing something wrong or extremely hacky.

Leave a Comment