

Global Admin Variable, It tells which page is on now. You can use these snippets as per your needs, all you need to set post type.ĭon’t forget to change the script and style handle name and path to the file.
#Wordpress enqueue style code
To enqueue scripts & style in posts, pages and custom post types page, code snippets are given below. Wp_enqueue_script('admin-your-js-file-handle-name', get_template_directory_uri().'/js/your-js-file.js') Īdd_action( 'admin_enqueue_scripts', 'enqueuing_admin_scripts' ) Įnqueue Scripts & Style in WordPress Admin for Posts | Pages | Custom Post Types Wp_enqueue_style('admin-your-css-file-handle-name', get_template_directory_uri().'/css/your-css-file.css') Don’t forget to change the script and style handle name and path to the file. This hook will be the same for both scripts and style.Īdd this code to functions.php file to add scripts and styles in WordPress admin for all pages. To enqueue any scripts and styles in admin, WordPress provides a hook admin_enequeue_scripts.

Enqueue Scripts & Style in WordPress Admin for All Pages Contents Description Parameters Source Related Uses Used By Changelog User Contributed Notes Description If the theme has opted-in to separate-styles loading, then the stylesheet will be enqueued on-render, otherwise when the block inits. You can add those code snippets into your theme’s functions.php file with their respective parameters. Enqueues a stylesheet for a specific block.

To enqueue scripts and styles in WordPress admin pages and login pages, code snippets are given below. Since most users run WordPress with a theme and several plugins, developers are advised to use the correct method of loading scripts into WordPress. WordPress has an enqueuing system for adding local/remote scripts along with styles to prevent conflicts with plug-ins. Are you working with custom theme or plugin?, then there can be a chance where you need to enqueue scripts and styles in WordPress admin pages or any specific admin page or may be login page. Enqueue scripts and styles in WordPress the correct way.
