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

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. Can I have a condition for hooks to load only certain pages?

Related posts

Leave a Reply

1 comment

  1. 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
      }
    }