Support » Plugins » wp_head on certain admin pages only

  • Hey there,

    I’m trying to add some JS and CSS code in the admin header section. Works fine. But I do want the code only to appear on certain pages like edit.php or edit-pages.php.

    add_action('admin_head-xxxx', 'function' );

    seems not to work for me. What do I have to fill xxxx with? I tried

    add_action('admin_head-edit', 'function' );

    but it didnt work.

    Any suggestions?

Viewing 8 replies - 1 through 8 (of 8 total)
  • whooami



    did you look over the hooks? You cant, and dont, add on stuff to pre-existing hooks.

    whats there is whats there, they dont accept changes.

    admin_head-xxxx isnt a hook regardless of what you substitute for the xx’s, in other words.




    what I have done under a slightly different scenario was create and add my own hooks. You modify core WP files doing this. It was very easy for me to do, but then I do my homework and try to read about things before attempting to do them.

    Well, the Codex sais there’s such a hook: like admin_head-(page_hook) or admin_head-(plugin_page)…

    Well, now that there really doesnt seem to be a working hook I’ll try some workaround. Just wondered why admin_head-(page_hook) didnt work for me though its listed in the official Codex.

    edit. And editing core files isnt an option. I cant force my plugin users to hack their WP. 😉




    I apologize,

    I had NO idea about that. My sincerest apologies, really.

    I assume then, since youve seen that (and I had not!!), that you noticed that the variations read as if theyre intended/reserved for plugin generated pages..and not core files like edit.php, etc.

    Well, no need to apologize, dude. 🙂

    Those hooks might be for plugin pages only, but admin_head-(page_hook) reads different to admin_head-(plugin_page)… if they’re both meant for plugin pages only, someone should point that out in the codex.

    I believe the hooks you’re talking about are only for plugin pages. I think the difference in admin_head-(plugin_page) to admin_head-(page_hook) is the value you put for the value in parentheses. For plugin_page, you would probably put the name of the file that your page is generated from whereas with with page_hook you do something like this:

    $page = add_manage_page('All','the','arguments','etc.');

    To get things to show up on just the write post and page interfaces, I just did a simple check against the current URL, and that’s the best answer to the problem I’ve seen.

    nickohrn: Yeah, that’s what I’ll be doing next. I still wonder why the dev team didnt think of adding a hook for that need, though.

    add_action( 'admin_menu', 'aa_pro_setup_options' );
    function aa_pro_setup_options(){
      $page=add_options_page( 'AskApache Pro', 'askapache-pro', 'AA Pro', 'askapache-pro', 8, basename(__FILE__), 'aa_pro_main' );
      add_action( 'admin_head-'. $page, 'aa_pro_admin_header' );
    function aa_pro_admin_header(){
      echo '<p>Only ran when on the plugin page!</p>';

    This works perfectly for the askapache plugins.. took me awhile to find how to do it though.. enjoy!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘wp_head on certain admin pages only’ is closed to new replies.