Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In the Wordpress admin, how can I programmatically find out which page (themes.php, widgets.php, etc.) I'm on?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You can determine that with wordpress' get_current_screen() function. It will not return just a page name though, it will give you an object containing a bunch of different data on what screen you're on.

share|improve this answer
1  
For a properly formatted output of that function, use this code chunk - <pre><?php print_r(get_current_screen()); ?></pre> - it makes for a nice nested list, I use it whenever I need to echo any object or array-based variable. –  SickHippie Mar 6 '12 at 18:02
    
Weird... get_current_screen() is reported as undefined. Do I have to declare a global variable into scope, or anything else? –  julien_c Mar 6 '12 at 18:03
    
How are you calling it up? –  SickHippie Mar 6 '12 at 18:03
2  
I would probably use admin_head myself, but look here - wordpress.org/support/topic/… - to see an example that's working. Maybe you can take it from there? –  SickHippie Mar 6 '12 at 18:16
2  
You can also use admin_menu, but _admin_menu is too early and adminmenu too late. :) –  kaiser Mar 6 '12 at 18:20
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.