web creating

POROA

【WordPress】twentysixteenのheaderにかいてあるScriptの消し方

WordPressをインストールすると
デフォルトで入っている「twentysixteen」
こちらも中々不必要なコードが入っています。

私もそうですが、テンプレート修正して使用しようと思っている方は、このソース邪魔だなぁと思ってしまいます。

そういった場合はfunctions.phpを修正しましょう。

■Modernizr

参考サイト:http://geekpraise.com/twentyfifteen-head
Modernizrを使う場合に「no-js」を「js」に変更するために記述しているようです。
使用しないならば消して問題ないでしょう。

【表示HTML】
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%3E(function(html)%7Bhtml.className%20%3D%20html.className.replace(%2F%5Cbno-js%5Cb%2F%2C'js')%7D)(document.documentElement)%3B%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;script&gt;" title="&lt;script&gt;" />

【削除】 functions.phpの228行目を消す
/**
 * Handles JavaScript detection.
 *
 * Adds a `js` class to the root `<html>` element when JavaScript is detected.
 *
 * @since Twenty Sixteen 1.0
 */
function twentysixteen_javascript_detection() {
	echo "<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-wp-preserve="%3Cscript%3E(function(html)%7Bhtml.className%20%3D%20html.className.replace(%2F%5Cbno-js%5Cb%2F%2C'js')%7D)(document.documentElement)%3B%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="&lt;script&gt;" title="&lt;script&gt;" />\n";
}
add_action( 'wp_head', 'twentysixteen_javascript_detection', 0 );

■googlefont

googleフォントを読み込んでいます。
いらない方は削除しましょう。

【表示HTML】
<link rel='stylesheet' id='twentysixteen-fonts-css' href='https://fonts.googleapis.com/css?family=Merriweather%3A400%2C700%2C900%2C400italic%2C700italic%2C900italic%7CInconsolata%3A400&#038;subset=latin%2Clatin-ext' type='text/css' media='all' />

【削除】 functions.phpの234行を削除
// Add custom fonts, used in the main stylesheet.
	wp_enqueue_style( 'twentysixteen-fonts', twentysixteen_fonts_url(), array(), null );


■genericons.css

ウェブアイコンgenericonsを使用するためのCSSです。
不必要なら削除しましょう。

<link rel='stylesheet' id='genericons-css'  href='http:ドメイン/wp-content/themes/twentysixteen/genericons/genericons.css?ver=3.4.1'

【削除】 functions.php 237行
// Add Genericons, used in the main stylesheet.
	wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.4.1' );

■style.css

テンプレートのデフォルトCSSです。こちらも、必要でない場合は消しましょう。

[if lt IE 10]移行はIEのCSSハックのCSSです。

こちらもいらなければ消しましょう。

【表示HTML】
<link rel='stylesheet' id='twentysixteen-style-css'  href='http://www.poroanet.com/blog/wp-content/themes/poroablog/style.css?ver=4.6' type='text/css' media='all' />
<!--[if lt IE 10]>
<link rel='stylesheet' id='twentysixteen-ie-css' href='http://www.poroanet.com/blog/wp-content/themes/poroablog/css/ie.css?ver=20160412' type='text/css' media='all' />
<![endif]-->
<!--[if lt IE 9]>
<link rel='stylesheet' id='twentysixteen-ie8-css' href='http://www.poroanet.com/blog/wp-content/themes/poroablog/css/ie8.css?ver=20160412' type='text/css' media='all' />
<![endif]-->
<!--[if lt IE 8]>
<link rel='stylesheet' id='twentysixteen-ie7-css' href='http://www.poroanet.com/blog/wp-content/themes/poroablog/css/ie7.css?ver=20160412' type='text/css' media='all' />
<![endif]-->

【削除】 functions.php 240行
// Theme stylesheet.
	wp_enqueue_style( 'twentysixteen-style', get_stylesheet_uri() );
これを削除すると一緒にIE用のCSSも消えます。

下記コードを消すことで個別に消すこともできます。
ただし、sytle.cssが残ってしまいます。(もし、個別の方法があれば教えてください)すべて消す場合は上記コードを削除するだけでいいでしょう。

// Load the Internet Explorer specific stylesheet.
	wp_enqueue_style( 'twentysixteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentysixteen-style' ), '20160412' );
	wp_style_add_data( 'twentysixteen-ie', 'conditional', 'lt IE 10' );

	// Load the Internet Explorer 8 specific stylesheet.
	wp_enqueue_style( 'twentysixteen-ie8', get_template_directory_uri() . '/css/ie8.css', array( 'twentysixteen-style' ), '20160412' );
	wp_style_add_data( 'twentysixteen-ie8', 'conditional', 'lt IE 9' );

	// Load the Internet Explorer 7 specific stylesheet.
	wp_enqueue_style( 'twentysixteen-ie7', get_template_directory_uri() . '/css/ie7.css', array( 'twentysixteen-style' ), '20160412' );
	wp_style_add_data( 'twentysixteen-ie7', 'conditional', 'lt IE 8' );

■IE9用変換用js

上記同様IE用のハックですがこちらだけ、別みたいです。
これも必要ない場合はこちらを削除しましょう。

【表示HTML】
<!--[if lt IE 9]>
<script type='text/javascript' src='http://www.poroanet.com/blog/wp-content/themes/poroablog/js/html5.js?ver=3.7.3'></script>
<![endif]-->

【削除】 functions.phpの255行目
// Load the html5 shiv.
	wp_enqueue_script( 'twentysixteen-html5', get_template_directory_uri() . '/js/html5.js', array(), '3.7.3' );
	wp_script_add_data( 'twentysixteen-html5', 'conditional', 'lt IE 9' );
著者:poroa | 投稿日:2016年08月12日 | カテゴリ:WordPress
■最新記事
■カテゴリ一覧
CSS
Excel
Google Analytics
HTML
jQuery
PHP
SEO
WordPress
ホームページ作成
ホームページ作成講座
未分類
楽天
■アーカイブ
2018年9月
2016年12月
2016年11月
2016年10月
2016年9月
2016年8月
■ランキング