add_action( 'plugins_loaded', 'boj_footer_message_plugin_setup' );
function boj_footer_message_plugin_setup() {
/* 添加 footer 信息动作 */
add_action( 'wp_footer', 'boj_example_footer_message', 100 );
}
function boj_example_footer_message() {
echo '基于 <a href="http://tui8.com" >推吧自媒体 </a>架设。';
}
这个作为钩子怎么添加到functions
“plugins_loaded”这个钩子是插件开发的时候用到的,在所有用户启用的插件都被 WordPress 加载之后执行。
你如果想直接在functions.php中添加一个给footer添加一个动作,直接用你的代码中去掉“plugins_loaded”就行了吧:
function boj_example_footer_message() {
echo '基于 <a href="http://tui8.com" >推吧自媒体 </a>架设。';
}
add_action( 'wp_footer', 'boj_example_footer_message', 100 );
add_action() 就是把你自定义的function记录了下来。
并不是所有的function都可以任意挂载,下面是wp_footer的源码,里面调用了do_action( 'wp_footer' )
就是把之前add的funcion列表遍历执行了一遍,钩子这个名字听起来怪怪得,其实就是任务列表+1个挂载点
function wp_footer() {
/**
* Print scripts or data before the closing body tag on the front end.
*
* @since 1.5.1
*/
do_action( 'wp_footer' );
}