WordPressのテーマ作成~WordPressのheadにデフォルトで入っているけどいらないやつ削除しよう~
投稿日
更新日
WordPressでテーマ作成をしていると、自動的にhead内に表示される内容があります。
必要ないものもあるので、functions.phpに削除の処理を書いて、表示されないようにしていきました。
meta name=”generator”を削除する
1 |
<meta name="generator" content="WordPress バージョン" /> |
functions.phpに以下のように書きます。
1 2 3 |
function theme_remove() { remove_action( 'wp_head', 'wp_generator' ); } |
link rel=”wlwmanifest”を削除する
ウィンドウズタイプライターという、ブログを投稿できるソフトを利用するための内容なので、それを利用しない場合はいらないので、削除します。
1 |
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://vccw.dev/wp-includes/wlwmanifest.xml" /> |
functions.php内のさっきのtheme_remove()内に下記を追加します。
1 |
remove_action( 'wp_head', 'wlwmanifest_link' ); |
link rel=”EditURI”を削除する
外部の投稿ツールからWordPressに記事の投稿を行う時に必要な設定ですが、外部ツールからの投稿を行わないので削除します。
1 |
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://vccw.dev/xmlrpc.php?rsd" /> |
functions.php内のさっきのtheme_remove()内に下記を追加します。
1 |
remove_action( 'wp_head', 'rsd_link' ); |
link rel=”dns-prefetch”を削除する
WordPressでは、絵文字をCDNしているドメインをプリフェッチしている設定がありますが絵文字を使用しないので今回は削除します。
1 |
<link rel='dns-prefetch' href='//s.w.org' /> |
functions.php内のさっきのtheme_remove()内に下記を追加します。
1 |
add_filter( 'emoji_svg_url', '__return_false' ); |
絵文字用のJavaScriptとStyleSheetを削除する
絵文字用のJavaScriptとStyleSheetもhead要素内に出力されるので絵文字を使用しないので削除します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<script type="text/javascript"> window._wpemojiSettings = {"baseUrl":"https:\/\/s.w.org\/images\/core\/emoji\/2.3\/72x72\/","ext":".png","svgUrl":false,"svgExt":".svg","source":{"concatemoji":"http:\/\/vccw.dev\/wp-includes\/js\/wp-emoji-release.min.js?ver=4.8.2"}}; !function(a,b,c){function d(a){var b,c,d,e,f=String.fromCharCode;if(!k||!k.fillText)return!1;switch(k.clearRect(0,0,j.width,j.height),k.textBaseline="top",k.font="600 32px Arial",a){case"flag":return k.fillText(f(55356,56826,55356,56819),0,0),b=j.toDataURL(),k.clearRect(0,0,j.width,j.height),k.fillText(f(55356,56826,8203,55356,56819),0,0),c=j.toDataURL(),b!==c&&(k.clearRect(0,0,j.width,j.height),k.fillText(f(55356,57332,56128,56423,56128,56418,56128,56421,56128,56430,56128,56423,56128,56447),0,0),b=j.toDataURL(),k.clearRect(0,0,j.width,j.height),k.fillText(f(55356,57332,8203,56128,56423,8203,56128,56418,8203,56128,56421,8203,56128,56430,8203,56128,56423,8203,56128,56447),0,0),c=j.toDataURL(),b!==c);case"emoji4":return k.fillText(f(55358,56794,8205,9794,65039),0,0),d=j.toDataURL(),k.clearRect(0,0,j.width,j.height),k.fillText(f(55358,56794,8203,9794,65039),0,0),e=j.toDataURL(),d!==e}return!1}function e(a){var c=b.createElement("script");c.src=a,c.defer=c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f,g,h,i,j=b.createElement("canvas"),k=j.getContext&&j.getContext("2d");for(i=Array("flag","emoji4"),c.supports={everything:!0,everythingExceptFlag:!0},h=0;h<i.length;h++)c.supports[i[h]]=d(i[h]),c.supports.everything=c.supports.everything&&c.supports[i[h]],"flag"!==i[h]&&(c.supports.everythingExceptFlag=c.supports.everythingExceptFlag&&c.supports[i[h]]);c.supports.everythingExceptFlag=c.supports.everythingExceptFlag&&!c.supports.flag,c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.everything||(g=function(){c.readyCallback()},b.addEventListener?(b.addEventListener("DOMContentLoaded",g,!1),a.addEventListener("load",g,!1)):(a.attachEvent("onload",g),b.attachEvent("onreadystatechange",function(){"complete"===b.readyState&&c.readyCallback()})),f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings); </script> <style type="text/css"> img.wp-smiley, img.emoji { display: inline !important; border: none !important; box-shadow: none !important; height: 1em !important; width: 1em !important; margin: 0 .07em !important; vertical-align: -0.1em !important; background: none !important; padding: 0 !important; } </style> |
functions.php内のさっきのtheme_remove()内に下記を追加します。
1 2 3 4 |
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' ); |
結構いろいろ使わないもの入ってるので、必要ないものは削除しておこう!!
下記、参考にさせて頂きましたm(__)m
WordPressのヘッダー要素で必要ない情報を削除する方法