Support » Alpha/Beta/RC » How to tell if we’re on the dashboard?

  • Resolved Jick


    Is there a way to know when we’re on the main dashboard of WordPress? I’m developing a new plugin for the upcoming WordPress 2.7 and I’m adding a widget to the dashboard that needs some custom styling included in the <head> area. It only needs to be included if we’re on the main dashboard page.

    I’ve tried this:

    if(strpos($_SERVER['REQUEST_URI'], 'index.php') {
      // Add styles...

    But that only works when you’re actually on /wp-admin/index.php and not when you’re just on /wp-admin/. Also, I was really looking for a more reliable method than that. Like a built-in function such as is_page() or something…

    Any help on this issue would be greatly appreciated…

Viewing 5 replies - 1 through 5 (of 5 total)
  • add_action('admin_head-index.php', 'your_function');
    function your_function() {
    	// Do stuff;

    This works for all of the core WordPress PHP files which have a user-facing administration element (i.e. post.php, post-new.php, etc.)

    Also you could use $_SERVER['REQUEST_URI'] and compare against bloginfo('wpurl').'/wp-admin/' — this will also work, as WordPress always appends a trailing slash to the URI.

    add_action('admin_head-index.php', 'your_function');
    That works perfectly! Thank you so much!

    I never knew about that… Do you know if there is any documentation on that or is it just one of those “known only by those who already know about it” things? 😛

    I’ll also keep in mind your other suggestion.

    Thanks again!

    Oh, one other thing…

    Do you know if that same functionality can be used for plugin pages? So, like, something like this:

    add_action('admin_head-my-plugin-page', 'your_function');

    Thanks again for your help. 🙂

    No problem.

    Anyway, the first solution, no that is not a well-documented feature. But to answer your second question — that can be done, and that IS documented.

    Have a look here:
    Action: admin_head-(plugin_page)

    You’ll notice that (plugin_page) is assigned as a variable prior to setting up the action. You have probably already written that line of code; just assign it to a variable, and you will be able to create the action from it.

    That’s great! Thanks for the link. I really appreciate it. Thank you very much!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to tell if we’re on the dashboard?’ is closed to new replies.