Load a stylesheet or Scripts on specific admin pages

I was working on some project and there is a requirement that I would like to load a style-sheet on specific admin pages. e.g

  • post.php?post=3&action=edit
  • post.php?post=10&action=edit
  • post.php?post=15&action=edit

WordPress is very rich CMS and application and we can do anything I believe. I know there is a way to do this and after reading codex a lot I found get_current_screen function. This function returns an object that includes the screen’s ID, base, post type, and taxonomy, among other data points. I would simply like to use get_current_screen in my functions.php to determine if the admin page loaded is 1 of the 3 pages and if so load a css file.

wordpress solution for all needs
  • Facebook
  • Twitter
  • Google+
  • LinkedIn
  • Pinterest

We can get the current screen and set the page IDs we would like to include any scripts or styles. We then make sure that there is a $_GET['post'] set which holds our post->ID and we also want to make sure we’re in the correct post type (though you could probably skip the whole current screen thing entirely and just use $_GET). We then check to see if the current post ID is in our array of accepted IDs and if so: enqueue. Here is a sample code from codex that can help us.

Thanks Howdy_McGee for this solution.

About Howdy_McGee

I’m a Web Developer who is constantly learning the trade. I’ve built and manage 50+ WordPress websites with the help of the talented Web Designers around me. I’m currently looking for ways I can help the WordPress community grow and maintain its awesomeness!

Web consultant and Web Designer with over 7 years of professional and creative experience. Jamil is passionate about creating modern and user friendly websites that help businesses attract more customers and increase sales. He received bachelor and master in Business Administration and also co-founder of www.prepareddevelopment.com

Pin It on Pinterest

Share This