开发者

Wordpress: How can I hook only on certain pages? Can I even do that?

开发者 https://www.devze.com 2023-03-07 18:22 出处:网络
So I created a action add_action( \'header\',\'admin_bar\', 8 );, so that it loads in the header. However, I don\'t want it to load on certain pages, for example, post-new.php. Ca开发者_如何学Pythonn

So I created a action add_action( 'header', 'admin_bar', 8 );, so that it loads in the header. However, I don't want it to load on certain pages, for example, post-new.php. Ca开发者_如何学Pythonn I have a condition for hooks to load only certain pages?


I believe there is a $pagenow global. not sure if it's still there but you could var_dump($pagenow) on the pages you want to exclude to find the value then do something like this in your function...

function admin_bar() {
  global $pagenow;
  if ( 'post-new' != $pagenow || 'dashboard' != $pagenow ) {
   //execute code
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消