WordPress のテーマはストークを使用している。
ヘッダーの中で無駄なCSSやJSを読み込んでいるのを止めてみた。
投稿記事ページか否かで読み込まないものを分ける。
トップページ、カテゴリー一覧ページでは必要のないJS, CSSがいくつもある。
以下のように functions.php に記述するとうまくいった。
表示も乱れていない。
function my_delete_plugin_styles() {
wp_deregister_style( 'dashicons' );
wp_deregister_style( 'wpstatistics-css' );
wp_deregister_style( 'emoji' );
if( is_singular() ){
wp_deregister_style( 'slick' );
}else{
wp_deregister_style( 'photoswipe-lib' );
wp_deregister_style( 'photoswipe-skin' );
wp_deregister_style( 'pz-linkcard' );
wp_deregister_style( 'toc-screen' );
wp_deregister_style( 'whats-new-style' );
wp_deregister_style( 'jetpack_css' );
wp_deregister_style( 'shortcode' );
}
}
add_action( 'wp_enqueue_scripts', 'my_delete_plugin_styles', 100 );
function my_delete_deregister_scripts() {
wp_deregister_script( 'emoji' );
wp_deregister_script( 'masonry.pkgd.min' );
wp_deregister_script( 'css-modernizr' );
wp_deregister_script( 'wow' );
wp_deregister_script( 'imagesloaded' );
if( is_singular() ){
wp_deregister_script( 'slick' );
}else{
wp_deregister_script( 'photoswipe-lib' );
wp_deregister_script( 'photoswipe-ui-default' );
wp_deregister_script( 'photoswipe' );
wp_deregister_script( 'toc-front' );
wp_deregister_script( 'my-admin-js' );
}
}
add_action( 'wp_enqueue_scripts', 'my_delete_deregister_scripts', 100 );
//不要なヘッダー除去
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_shortlink_wp_head');
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
add_filter( 'jetpack_implode_frontend_css', '__return_false' );



