1

Is there any way to change the order of filters for e.g. the_content before they are applied? What I currently have is the following ideas:

/**
 * Print all filters for some hook.
 */
function print_filters_for( $hook = '' ) {
    global $wp_filter;
    if( empty( $hook ) || !isset( $wp_filter[$hook] ) )
        return;

    print '<pre>';
    print_r( $wp_filter[$hook] );
    print '</pre>';
}

add_action('template_redirect','print_filters');

function print_filters() {
    print_r(print_filters_for('the_content'));die;
}

This gives me the filters, but I can not think of any comfortable way to change their priorities.

add_filter( 'the_content', 'my_content_filter_priority_reorder', 0 );

function my_content_filter_priority_reorder($the_content) {
    // reorder filter priorities
    return $the_content;
}

Has anybody already had this problem and knows how to possibly change this?

2

If you know the existing callback and priority you can just remove the filters and then add again at a different priority:

remove_filter( 'the_content', 'convert_smilies', 20 );
add_filter( 'the_content', 'convert_smilies', 30 );

remove_filter( 'the_content', 'capital_P_dangit', 11 );
add_filter( 'the_content', 'capital_P_dangit', 20 );
  • That seems basically the correct way to do it, congrats on 10K reputation 😎 Do you know a method to extract a filters registered plain names such you can proceed with reordering them? – Blackbam Jul 11 '18 at 11:45
  • 1
    You'll need to print them out the way you have in your question. The tricky part is that hooked functions won't all just be a simple function name. Hooks are callables and can require a reference to other objects to remove. See this old question and answer on findind and removing hooks. – Jacob Peattie Jul 12 '18 at 2:00

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.