<head>内のタグを削除する
WordPressでは標準で<head>タグの中に様々なタグが自動出力されます。不要な場合、これらは削除することができます。
※ 削除する場合は本当に必要ないか確認したのち削除するようにしてください。
目次
RSS
下記はRSSリーダーのソフトでサイトの更新情報をチェックしたいユーザーのために必要になるタグです。
1 2 3 |
<link rel="alternate" type="application/rss+xml" title="○○サイト » フィード" href="http://example.com/feed" /> <link rel="alternate" type="application/rss+xml" title="○○サイト » コメントフィード" href="http://example.com/comments/feed" /> <link rel="alternate" type="application/rss+xml" title="○○サイト » ○○記事 のコメントのフィード" href="http://example.com/XXXX/feed" /> |
このタグを削除したい場合、functions.phpに下記のように記載します。(削除すると、ユーザーがRSSリーダーで更新情報を受け取ることが難しくなります)
1 2 |
remove_action('wp_head', 'feed_links', 2); remove_action('wp_head', 'feed_links_extra', 3); |
「RSSやAtomの配信を停止する」も参考にしてください。
<link rel="EditURI">
<link rel="EditURI">
は、外部の投稿ツールからWordPressに記事を投稿する際に必要なタグです。
1 |
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="..." /> |
このタグを削除したい場合、functions.phpに下記のように記載します。(削除すると、外部の投稿ツールからの投稿ができなくなる可能性があります(未検証)。WordPressのiOSアプリはこのタグがなくても特に問題なく投稿できていました)
1 |
remove_action('wp_head', 'rsd_link'); |
<link rel="wlwmanifest">
1 |
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="..." /> |
<link rel="wlwmanifest">
は、Windows Live WriterというWindows用のブログ投稿ソフトからWordPressに記事を投稿する際に必要なタグです。
このタグを削除したい場合、functions.phpに下記のように記載します。(削除すると、Windows Live Writerからの投稿ができなくなります)
1 |
remove_action('wp_head', 'wlwmanifest_link'); |
<link rel="next">, <link rel="prev">
<link rel="next">
, <link rel="prev">
は、投稿の前後にある投稿へのリンクです。
1 2 |
<link rel='prev' title='○○記事' href='...' /> <link rel='next' title='○○記事' href='...' /> |
このタグを削除したい場合、functions.phpに下記のように記載します。(削除しても特に影響はありません。ただ、一部のJavaScriptのライブラリなどではこのタグをもとに記事を自動読み込み・無限スクロールする機能を搭載しているかもしれません)
1 |
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
<link rel="canonical">
<link rel="canonical">
は、あるページ(投稿等)が複数のURLでアクセスできる場合に正しいURLを示すタグです。
1 |
<link rel="canonical" href="..."> |
このタグを削除したい場合、functions.phpに下記のように記載します。(削除すると、SEO的に影響が出る可能性があります。→参考)
1 |
remove_action('wp_head', 'rel_canonical'); |
<meta name="generator">
<meta name="generator">
は、サイトがどのようなシステムを使って生成されたかを示すタグです。
1 |
<meta name="generator" content="WordPress X.X"> |
このタグを削除したい場合、functions.phpに下記のように記載します。(削除しても特に影響はありません)
1 |
remove_action('wp_head', 'wp_generator'); |
<link rel="shortlink">
<link rel="stortlink">
は、投稿ページなどで短いURL(サイトのURL/?p=記事番号
)を示すタグです。
1 |
<link rel='shortlink' href='...' /> |
このタグを削除したい場合、functions.phpに下記のように記載します。(削除しても特に影響はないと思いますが、未検証です)
1 |
remove_action('wp_head', 'wp_shortlink_wp_head'); |
絵文字
下記の<script>
および<style>
は、WordPressの絵文字機能の一部です。WordPress 4.2から追加されています。
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":"http:\/\/s.w.org\/images\/core\/emoji\/72x72\/","ext":".png","source":{"concatemoji":"http:\/\/example.com\/wp-includes\/js\/wp-emoji-release.min.js?ver=4.4.1"}}; !function(a,b,c){function d(a){var c,d=b.createElement("canvas"),e=d.getContext&&d.getContext("2d");return e&&e.fillText?(e.textBaseline="top",e.font="600 32px Arial","flag"===a?(e.fillText(String.fromCharCode(55356,56806,55356,56826),0,0),d.toDataURL().length>3e3):"diversity"===a?(e.fillText(String.fromCharCode(55356,57221),0,0),c=e.getImageData(16,16,1,1).data.toString(),e.fillText(String.fromCharCode(55356,57221,55356,57343),0,0),c!==e.getImageData(16,16,1,1).data.toString()):("simple"===a?e.fillText(String.fromCharCode(55357,56835),0,0):e.fillText(String.fromCharCode(55356,57135),0,0),0!==e.getImageData(16,16,1,1).data[0])):!1}function e(a){var c=b.createElement("script");c.src=a,c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f,g;c.supports={simple:d("simple"),flag:d("flag"),unicode8:d("unicode8"),diversity:d("diversity")},c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.simple&&c.supports.flag&&c.supports.unicode8&&c.supports.diversity||(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に下記のように記載します。(削除すると、投稿などに絵文字を使用しても絵文字が表示されなくなります)
1 2 |
remove_action('wp_head', 'print_emoji_detection_script', 7); remove_action('wp_print_styles', 'print_emoji_styles'); |
oEmbed
oEmbedは外部サイトの情報を埋め込むための機能です。4.4からWordPress自身をほかのサイトに埋め込みできるようになったため、下記のコードが追加されるようになりました。
1 2 3 |
<link rel="alternate" type="application/json+oembed" href="http://example.com/wp-json/oembed/1.0/embed?url=記事URL" /> <link rel="alternate" type="text/xml+oembed" href="http://example.com/wp-json/oembed/1.0/embed?url=記事URL;format=xml" /> <script type='text/javascript' src='http://example.com/wp-includes/js/wp-embed.min.js?ver=X.X'></script> |
このタグを削除したい場合、functions.phpに下記のように記載します。(削除すると、ほかのサイトがあなたのサイトをoEmbedで埋め込むことができなくなります)
1 2 3 |
remove_action('wp_head','rest_output_link_wp_head'); remove_action('wp_head','wp_oembed_add_discovery_links'); remove_action('wp_head','wp_oembed_add_host_js'); |
全て削除する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
// <link rel="alternate" type="application/rss+xml" title="" href="..." /> remove_action('wp_head', 'feed_links', 2); // <link rel="alternate" type="application/rss+xml" title="" href="..." /> remove_action('wp_head', 'feed_links_extra', 3); // <link rel="EditURI" type="application/rsd+xml" title="RSD" href="..." /> remove_action('wp_head', 'rsd_link'); // <link rel="wlwmanifest" type="application/wlwmanifest+xml" href="..." /> remove_action('wp_head', 'wlwmanifest_link'); // <link rel="next" href="...">, <link rel="prev" href=""> remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); // <link rel="canonical" href="..."> remove_action('wp_head', 'rel_canonical'); // <meta name="generator" content="WordPress X.X"> remove_action('wp_head', 'wp_generator'); // <link rel='shortlink' href='...' /> 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'); // <link rel='https://api.w.org/' href='...' /> remove_action('wp_head', 'rest_output_link_wp_head'); // <link rel="alternate" type="application/json+oembed" href="http://example.com/wp-json/oembed/1.0/embed?url=記事URL" /> ほか remove_action('wp_head','wp_oembed_add_discovery_links'); // <script type='text/javascript' src='http://example.com/wp-includes/js/wp-embed.min.js?ver=X.X'></script> remove_action('wp_head','wp_oembed_add_host_js'); |
その他
下記は現在のWordPress(4.4)では使用されていないため不要です。
1 2 3 |
remove_action('wp_head', 'index_rel_link'); remove_action('wp_head', 'parent_post_rel_link'); remove_action('wp_head', 'start_post_rel_link'); |