【WordPress】初期設定の覚書

電脳備忘録

本記事のソースコードの利用によって生じた損害について、当方は一切の責任を負いません。ご自身の判断と責任のもとで参照・ご利用ください。

この記事は最終更新から4年以上経過しています。

とにかくWordPressが勝手に吐き出すコードを阻止したい人なので、毎回function.phpに追記するのですが、以前作業したときのファイルを探すのも面倒くさいのでここに記載しておくことにします。完全に自分向けの備忘録です。

//諸々非表示
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');

// 絵文字用JS・CSSを非表示にする
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_action('wp_head', 'feed_links_extra', 3);

//css非表示
remove_action( 'wp_head', 'wp_print_styles',8);

//自動Pタグ削除
remove_filter('the_excerpt', 'wpautop');
remove_filter('term_description','wpautop');

function disable_page_wpautop() {
  if ( is_page() ) remove_filter( 'the_content', 'wpautop' );
}
add_action( 'wp', 'disable_page_wpautop' );


//WPデフォルトのjQueryをキャンセル
function delete_jquery() {
  if (!is_admin()) {
    wp_deregister_script('jquery');
  }
}
add_action('init', 'delete_jquery');

// DNSプリフェッチ設定の削除 
add_filter( 'emoji_svg_url', '__return_false' );


//テンプレートのスタイルをキャンセル
function denqueue_parent_scripts() {
	$remove_styles = array( 'rec-style');
	foreach( $remove_styles as $target ) {
			if( wp_style_is($target) ) { // スタイルシートが登録済みかチェック
					wp_dequeue_style($target); // スタイルシートを削除する
			}
	}
}
add_action( 'wp_enqueue_scripts', 'denqueue_parent_scripts', 11 );

//勝手に吐き出すtitleを阻止
remove_action('wp_head', '_wp_render_title_tag', 1);
0%