WordPress üzerinde kullanılmayan CSS ve JS dosyaları siteyi yavaşlatabilir. Bu dosyalar WordPress’teki varsayılan dosyalar olabilir veya herhangi bir eklentiden gelmiş olabilir. Kullanılmayan bu dosyaları silerek web sitesini hızlandırabilir. Stil dosyalarını kaldırmak için aşağıda ihtiyacınız olan kodları functions.php dosyasına ekleyin.
/* Emoji Scripts Kaldırma */
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
/* Emoji CSS Kaldırma */
remove_action( 'wp_print_styles', 'print_emoji_styles' );
/* Global Style Kaldırma 'id="global-styles-inline-css"' */
remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' );
/* application/rss+xml Kaldır */
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
/* application/rsd+xml Kaldır */
remove_action( 'wp_head', 'rsd_link' );
/* application/wlwmanifest+xml Kaldır */
remove_action( 'wp_head', 'wlwmanifest_link' );
/* rel="shortlink" Kaldır */
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
/* Remove WordPress Generator */
remove_action( 'wp_head', 'wp_generator' );
<link rel=”stylesheet”> elementi ile eklenen CSS’i aşağıdaki kod ile kaldırabilirsiniz.
Aşağıdaki örnek kod <link rel='stylesheet' id='wp-block-library-css' href='' media='all' />
CSS kodunu kaldırmak için kullanılabilir. Kaldırılacak CSS bağlantısı, wp_dequeue_style
ve ID ile belirlenir, ID’nin sonunda “-css” son ekini kullanmak gerekli değildir.
/* Remove <link rel="stylesheet" CSS> */
add_action( 'wp_enqueue_scripts', 'remove_styles' );
function remove_styles() {
wp_dequeue_style( 'wp-block-library', get_stylesheet_uri() );
}
WordPress panelinde spefisik bir sayfadaki CSS dosyasını kaldırma için aşağıdaki kodu kullanın.
/* Remove Style On Spesific Page */
add_action('wp_print_styles','_remove_style',100);
function _remove_style(){
global $post;
$pageUrl = get_permalink($post->ID);
if( $pageUrl=='https://example.com/page1/' ) {
wp_dequeue_style('wp-block-library');
}
}
Kaynak: https://stackoverflow.com/questions/38633991/how-to-remove-style-css-on-specific-wordpress-page