WordPress Wednesdays: Get the Current Page

Web Development WordPress

I was writing some functions that are used in the admin for my commercial WordPress theme: Lucidity and stumbled upon a great variable in WordPress: $pagenow. This variable will return the current page you are on and is great form admin functions – especially those that you want to only make available on certain pages.

To use this – just add it to your functions as a global variable, then you can use it to load in specific js/functions:

global $pagenow;
if (($pagenow == 'admin.php') && ($_GET['page'] == 'sdac_appearance')) {}

This proved to be very helpful when dealing with some finicky JS.

3 thoughts on “WordPress Wednesdays: Get the Current Page”

  1. Jeff

    Thanks for sharing this function. I was working on a plugin the other day and this will come in handy when I get back to it!

    Reading back through your site now to see what other info I’ve missed.

  2. scott bothel

    Ugh! What a life saver you are this morning. My admin scripts were screwing up the media upload on post edits. Now they are isolated to the theme settings screen.
    Thanks!

  3. Jan

    You really saved my life, as WordPress 3.3 crashed my theme today and added my theme settings in post-new.php where they shouldn’t be.

Leave a Reply

Your email address will not be published.
*
*

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Random

Linkfest Thursdays: July 23, 2009

Here are some links I found interesting over the last week. Wii Sports Resort I am really looking forward to this. Archery, basketball, table tennis, and more. Get ready! AD Gallery Wow – another great jQuery gallery plugin. This combines all of my favorite functionalities in one. Import your WordPress blog into Facebook Hmm, I […]

From Twitter

Twitter Weekly Updates for 2009-07-18

IE 6 + Flash + weird JS = nightmare. # Just saw Public Enemies…amazing # I hate greeting cards, but would totally buy this if it was one: http://bit.ly/pKpQf # Check out the sweet new Topspin site: http://www.topspin.com (one of my latest site releases). Go WordPress! # Whoops – obviously not enough caffeine today: http://www.topspinmedia.com […]