טעינת סקריפטים וסגנונות רק בעמודי ניהול ספציפיים בכדי למנוע התנגשויות ולשמור על מהירות לוח הבקרה. לעוד על אופטימיזציה של טעינת סקריפטים.
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
);
} );הוסיפו ל-functions.php. הפרמטר $hook מציין איזה עמוד ניהול נטען. ערכים נפוצים: post.php, edit.php, upload.php, options-general.php.