STRIX | ストリックスマーケティング HP制作会社

STRIX | ストリックスマーケティング HP制作会社

wordpress関連

wp_headの中の不要なコードを削除する方法

1.コメントのフィードなどの表示削除


//コメントのフィードなどの表示削除
remove_action('wp_head', 'feed_links_extra', 3);

2.絵文字の表示削除


//絵文字の表示削除
function dis_emojis() {
     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' );
}
add_action( 'init', 'dis_emojis' );

3.インラインスタイル削除(html直書きstylesheet削除)


//インラインスタイル削除(html直書きstylesheet削除)
function remove_recent_comments_style(){
	global $wp_widget_factory;
	remove_action('wp_head', array( $wp_widget_factory->widgets['WP_Widget_Recent_Comments'], 'recent_comments_style' ));
}
add_action( 'widgets_init', 'remove_recent_comments_style' );

4.ブログ投稿ツールのためのタグ削除


//ブログ投稿ツールのためのタグ削除
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');

5.rel=”prev”とrel=”next”の表示削除


//rel=”prev”とrel=”next”の表示削除
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');

6.WordPressのバージョンの表示削除


//WordPressのバージョンの表示削除
remove_action('wp_head', 'wp_generator');

7.全てののバージョンの表示の削除


//全てののバージョンの表示の削除
function remove_cssjs_ver2( $src ) {
if ( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_cssjs_ver2', 9999 );
add_filter( 'script_loader_src', 'remove_cssjs_ver2', 9999 );

8.rel=”canonical”の表示削除


//rel=”canonical”の表示削除
remove_action('wp_head', 'rel_canonical');

9.wp_head内のjQueryを読み込ませない


//wp_head内のjQueryを読み込ませない
//※crayon syntaxが動かなくなる可能性あり
function my_delete_local_jquery() {
    wp_deregister_script('jquery');
}
add_action( 'wp_enqueue_scripts', 'my_delete_local_jquery' );

10.wp_head内のプラグインの不要なCSSを読み込まない


//wp_head内のプラグインの不要なCSSを読み込まない
function my_delete_plugin_files() {
    wp_dequeue_style('wp-pagenavi');
}
add_action( 'wp_enqueue_scripts', 'my_delete_plugin_files' );
/*※wp_dequeue_style関数の引数には、プラグインのハンドル名を入れます。
多くのプラグインでは、ID名から「-css」を除いたものがハンドル名になります。*/