Load scripts and styles only on specific WordPress admin pages to avoid conflicts and keep the dashboard fast. For more on optimizing script loading.
add_action( 'admin_enqueue_scripts', function ( $hook ) {
// Only load on the post edit screen
if ( $hook !== 'post.php' && $hook !== 'post-new.php' ) {
return;
}
wp_enqueue_style(
'savvy-admin-custom',
get_template_directory_uri() . '/css/admin-custom.css',
array(),
'1.0.0'
);
wp_enqueue_script(
'savvy-admin-custom',
get_template_directory_uri() . '/js/admin-custom.js',
array( 'jquery' ),
'1.0.0',
true
);
} );Add to functions.php. The $hook parameter tells you which admin page is loading. Common values: post.php, edit.php, upload.php, options-general.php.