At what priority does add_filter overwrite core functions?

I’m writing a plugin that adds some extra thumbnails, checkboxes, etc to the end of a post.

I’m trying to figure out how to use add_filter properly.

Read More

Basically, I’ve got

add_filter('the_content', 'do_some_magic_at_the_end');

And there is a corresponding do_some_magic_at_the_end function that takes $content and appends some stuff to it.

I want this filter to be added after all other filters. I don’t want it overwriting any other filter. The docs says default priority is 10, so I assume it is simply being added to a chain of filters that get run on the_content.

If I set the priority to 1, will it overwrite any core functions?

Related posts

Leave a Reply

2 comments

  1. There is no definitive answer to that because there is no limit to priorities high/low. Also plugins can be much less careful than core with this.

    • 11 is good number to be after default priority;
    • 20 to be late;
    • multiple thousands is good to be later than anyone who didn’t put more zeros in his thousands;
    • 9 is good number to be slightly earlier than default;
    • 1 to be really early;
    • -1 to be almost definitively first, because very few people remember that priorities can go negative.

    Overall if you want to be sure you are before other functions you will have to dump everything that is added to hook in your specific setup and debug through that. You might need to create wrapper function to add your filters at specific load stage or even move other filters around.

    And if you are making plugin for distribution you can guess, but you can’t be sure.

  2. You won’t overwrite anything. Each priority level is actually a list of filters to use. If you have several different things hooking into the same filter at the same priority, they all get run.