简体   繁体   中英

how to run custom wordpress hook action from plugin inside a theme?

I'm trying to write a functionality plugin for a WordPress theme. Now I'm stuck on how to run my custom hook in any place in my theme. This code is in my plugins file:

add_action( 'my_custom_hook_name', 'navi_h');

function navi_h(){
    echo "Hello world!"; //just for demo
}   

In my themes function.php I have the following:

function my_navi() {
        do_action('my_custom_hook_name');
}

In my themes header I have the following:

my_navi();

Am I missing some information for you?

You don't need to wrap do_action function inside other function. You just need to add the do_action function inside your theme where you want to appear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM