Steve Grunwell

Open-source contributor, speaker, and electronics tinkerer

Quick Tip: is_login_page() Function for WordPress

When building WordPress themes, I typically try to keep as much code as possible out of the head section of my template and instead rely on the wp_head() action hook. By putting all of my wp_register_script() and wp_register_style() calls in one function I have a single place to manage (theme) assets and their dependencies. At the bottom of the function I usually like to enqueue my global scripts and styles (ones that will always be present) but am careful to keep them from appearing in the WordPress administration area (if you’re dealing with custom admin scripts or styles obviously adjust this to fit your project):

Wait, what the heck is is_login_page()

Did you catch that? My approach uses a non-core function, is_login_page(), which detects if the current page is a login-style page. The code is adapted from TheDeadMedic’s answer to to a question on WordPress Answers.

Since is_admin() doesn’t include the login-type pages (wp-login.php and wp-register.php) – any form scripting or styles could potentially impact the login page. Using is_login_page() with the is_admin() conditional will let you keep your scripts and styles out of the core WordPress pages.

Previous

Quick Tip: Troubleshooting /etc/hosts issues

Next

Speaking at WordCamp Columbus 2013

2 Comments

  1. Peter

    Very helpful thanks!

Leave a Reply

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

Be excellent to each other.