WordPressの絵文字やEasy Table of Contents関係のファイルの読み込みを止めて軽量化する

WordPress標準でheadに追加される絵文字関係のファイルの読み込みを止める

WordPressは標準で絵文字の画像表示用に色々ファイルを読み込みますが、

当ブログのジャンル的にまず絵文字を使うことはないのでファイルの読み込みを止めておきます。😘

この処理を停止してもデータベースの文字コードがUTF8mbであれば絵文字は問題なく表示できるので。😂

functions.phpに以下を記述。

add_action('wp_enqueue_scripts', 'wpHeadCleanUp');

function wpHeadCleanUp()
{
    remove_action('wp_head', 'print_emoji_detection_script', 7);
    remove_action('admin_print_scripts', 'print_emoji_detection_script');
    remove_action('wp_print_styles', 'print_emoji_styles');
    remove_action('admin_print_styles', 'print_emoji_styles');
    remove_filter('the_content_feed', 'wp_staticize_emoji');
    remove_filter('comment_text_rss', 'wp_staticize_emoji');
    remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
}

Easy Table of Contents関連のファイルの読み込みを止める



WordPressに簡単に見出しを追加できるEasy Table of Contentsですが、

アニメーション効果など余計な機能のために色々とJSやCSSファイルをWordPressに追加してくれます。

見出し表示機能だけあれば十分なのでfunctions.phpに以下を記述してこれらの読み込みを停止しておきましょう。

add_action('wp_enqueue_scripts', 'etocCleanUp');

function etocCleanUp()
{
    //wp_deregister_style('ez-icomoon');
    //wp_deregister_style('ez-toc');
    wp_deregister_script('js-cookie');
    wp_deregister_script('jquery-smooth-scroll');
    wp_deregister_script('jquery-sticky-kit');
    wp_deregister_script('jquery-waypoints');
    wp_deregister_script('ez-toc-js');
}

ez-icomoonとez-tocは読み込みを無効化するとほぼスタイルが適用されなくなるのでコメントアウトしています。
このあたりはプラグイン側の設定で変更できるようになるといいんですけどね。

まぁ余計な処理が気になるのであればfunctions.php内に見出し表示用の自作コードを書くのが一番…

なので当サイトは自作コードに変更しました。

WordPress関連記事



サイトについて

スマートフォンで海外FX&ビットコイン取引をする方法の解説。TariTali推し。

検索

カテゴリー