1

I need to add some content before post content.

I use follwoing code for it.

function theme_slug_filter_the_content( $content ) {
    $custom_content = 'My CONTENT GOES HERE';
    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'theme_slug_filter_the_content' );

Another plugin also add some content before post content.

Now my single post look like this.

Added Content From My Plugin
Added Content From Another Plugin
Post Content

But I need to change order. I need following way.

Added Content From Another Plugin
Added Content From My Plugin
Post Content

How do I do it?

2

add_filter() has other 2 optionals parameters (same for add_action()), the priority (default set to 10, and lower numbers correspond with earlier execution) and the number of args (default to 1).

You need to set your filter with the priority with an higher priority than the other plugin, assuming the other has its priority to the default one :

add_filter( 'the_content', 'theme_slug_filter_the_content',  99 );

That all!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.