WordPress Wednesdays: Get the Current Page

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.

About the Author...

Jennifer Zelazny

My name is Jennifer Zelazny and this site is a collection of my random thoughts and opinions. I am Penn Stater, WordPress developer, and a modern day explorer. I love exploring data, trends, and things that make the world a better place and sharing them here.

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.
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
*
*

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