How can I change action priority in Wordpress?

后端 未结 3 1147
北海茫月
北海茫月 2021-01-04 00:49

I\'m using the Thematic framework for a child theme. It has a number of hooks, but I\'m looking at thematic_header() in particular. The thematic_header() hook adds the follo

相关标签:
3条回答
  • 2021-01-04 01:16

    not to self-promote but I have done some work on this to provide a non-coding solution through a WordPress plugin called Prioritize Hooks. My plugin lets you set the priorities of various registered hooks through a UI and does the overriding in runtime so the code isn't modified.

    0 讨论(0)
  • 2021-01-04 01:21

    From WordPress

    if a hook was registered using a priority other than the default of 10, then you must also specify the priority in the call to remove_action().

    So I think you can first remove using following

    remove_action('thematic_header', 'thematic_brandingopen', 1);
    remove_action('thematic_header', 'thematic_access', 9);
    

    and the add again using different priority

    add_action('thematic_header', 'thematic_access', 1);
    add_action('thematic_header', 'thematic_brandingopen', 2);
    
    0 讨论(0)
  • 2021-01-04 01:24

    Just in case this helps someone, the variable actions are stored in is

    global $wp_filter;
    var_dump( $wp_filter[$hook_name] );
    

    Which is an array of arrays with the keys being the priority when the action was added.

    0 讨论(0)
提交回复
热议问题