Strawberry
Strawberry

Reputation: 67868

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?

Upvotes: 1

Views: 2902

Answers (1)

Darren
Darren

Reputation: 1533

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

Upvotes: 3

Related Questions