

Wp_register_style( 'wp_admin_css', get_bloginfo( 'stylesheet_directory' ). The majority of the plugins and themes (especially themes) that load JavaScript load it on every single page in the admin. To load it on a specific page you need to check the page before you enqueue the stylesheets. One of the things that often frustrates plugin and theme developers is other plugins and themes not properly loading JavaScript in the WordPress admin. This will add a stylesheet to every admin page you go on, but if you are building a WordPress plugin then you don't want to load the stylesheet on every page you want to just load it on a specific page. '/admin-style.css', false, '1.0.0' ) Īdd_action( 'admin_enqueue_scripts', 'load_wp_admin_style' ) Now you can create the callback function to use when you this action is called. To fix this sort of problem you can use the WordPress action admin_enqueue_script which will allow you to only load stylesheets in the admin area. Adding Javascript to the page is adding more weight to page even when the functionality can't be used. But the problem with this is that if you add something here the script will be added to the page even on the front-end. Normally in your Wordpress plugin you would just call wp enqueue script in the constructor of your plugin.

You might only want to add this so you can give extra functionality to your plugin in dashboard screen. For the login screen, use the loginenqueuescripts action hook. To call it on the administration screens, use the adminenqueuescripts action hook. For example you might want to add admin only CSS or admin only Javascript. The function should be called using the wpenqueuescripts action hook if you want to call it on the front-end of the site, like in the examples above. In order to do this, we had to tap into the adminprintstyles- action. We needed a CSS stylesheet and a JS file to be included on a WordPress plugin Settings page but not on any other WordPress Admin page. We ran across an issue while creating a WordPress plugin. When creating Wordpress plugins and themes, I find that a lot of the time you need to do something in the admin area only. Add Scripts/Styles to Specific WordPress Admin Pages.
