タグの人気記事
ワードプレスは便利な判明自分が書いた覚えがない不要なソースまで標準で吐き出してしまいます。
とりあえず私が不要と判断したものを抜粋してソースを紹介致します。
これをするだけでもサイトがかなり軽くなりますので一見の価値ありです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
// 標準で吐き出すソースを削除 remove_action('wp_head', 'print_emoji_detection_script', 7); remove_action('wp_print_styles', 'print_emoji_styles'); 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'); remove_action('template_redirect', 'rest_output_link_header', 11); remove_action('wp_head', 'wp_shortlink_wp_head'); // generatorを非表示にする remove_action('wp_head', 'wp_generator'); // EditURIを非表示にする remove_action('wp_head', 'rsd_link'); // wlwmanifestを非表示にする remove_action('wp_head', 'wlwmanifest_link'); // WordPress 4.6 DNS プリフェッチを非表示 function remove_dns_prefetch( $hints, $relation_type ) { if ( 'dns-prefetch' === $relation_type ) { return array_diff( wp_dependencies_unique_hosts(), $hints ); } return $hints; } add_filter( 'wp_resource_hints', 'remove_dns_prefetch', 10, 2 ); |
また、コンタクトフォーム7やWP-PageNavie等のプラグインを導入してる方はこちらも書いておきましょう。
下記ソースはスラッグが「contact」のものに対して機能します。
それ以外のスラッグで運営している方は、それぞれ修正して対応して下さい。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
// コンタクトフォームセブン必要な時だけ読み込み function my_contact_enqueue_scripts(){ wp_deregister_script('contact-form-7'); wp_deregister_style('contact-form-7'); if (is_page('contact')) { if (function_exists( 'wpcf7_enqueue_scripts')) { wpcf7_enqueue_scripts(); } if ( function_exists( 'wpcf7_enqueue_styles' ) ) { wpcf7_enqueue_styles(); } } } add_action( 'wp_enqueue_scripts', 'my_contact_enqueue_scripts'); //WP-PageNavieが読み込むCSSを削除 add_action( 'wp_enqueue_scripts', 'my_delete_plugin_styles' ); function my_delete_plugin_styles() { wp_deregister_style( 'wp-pagenavi' ); } |
Category : ワードプレス