緊急対応: WordPress 5.9 で追加される自動挿入コードを削除する

Takehiko Ono
8 min readFeb 7, 2022

HTMLソース中に意図しないくそコード、いえ 創造主からの偉大な思し召を全ての民へ余すことなく享受させてやるべく善意に基づき自動的に挿入される麗しきコード群 が多いことで定評のある WordPress ですが。

先日リリースされた Ver.5.9 でまたしてもくそコード、いえ創造主からの偉大な(中略)コード群が大量に追加されました。しかもHTMLソース中にインラインで堂々と。いったい主は何をお考えなのでしょう…。

新しい標準テーマに関連したもののようなのですが、カスタムテーマでサイト制作をしているのであれば不要のことの方が多い代物です。

さっそくコミュニティも荒れ模様となっているようですが、どうやらコード挿入時に使用される hook が判明したらしく、以下の設定を function.php に加えることで取り除くことが可能でした。

<?php

function clean_up_auto_inserted_codes () {
// remove SVG and global styles
remove_action('wp_enqueue_scripts', 'wp_enqueue_global_styles');

// remove wp_footer actions which add's global inline styles
remove_action('wp_footer', 'wp_enqueue_global_styles', 1);

// remove render_block filters which adding unnecessary stuff
remove_filter('render_block', 'wp_render_duotone_support');
remove_filter('render_block', 'wp_restore_group_inner_container');
remove_filter('render_block', 'wp_render_layout_support_flag');
}
add_action('after_setup_theme', 'clean_up_auto_inserted_codes');

?>

これに留まらず、自分がプロジェクトで制作しているテンプレートから削除している自動挿入のコードはバージョンアップを重ねるごとに増えてきており、今では以下のような始末に。

<?php

function clean_up_auto_inserted_codes () {

/* emoji関連 */
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');

remove_action('wp_head', 'wlwmanifest_link'); /* Windows Live Writer */
remove_action('wp_head', 'wp_generator'); /* WordPressバージョン */
remove_action('wp_head', 'rsd_link'); /* Really Simple Discoveryリンク */
remove_action('wp_head', 'feed_links', 2); /* フィードリンク関連 */
remove_action('wp_head', 'feed_links_extra', 3); /* コメントフィード */
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); /* ページネーション rel="next" / rel="prev" */
remove_action('wp_head', 'parent_post_rel_link'); /* ページネーション rel="up" */
remove_action('wp_head', 'start_post_rel_link'); /* ページネーション rel="start" */
remove_action('wp_head', 'start_post_rel_link'); /* ページネーション rel="index" */
remove_action('wp_head', 'rel_canonical'); /* canonical属性 */
remove_action('wp_head', 'wp_shortlink_wp_head'); /* 短縮URL */

/** =================================================================
* Remove Auto Inseted Codes from WordPress 4.4
* FYI: https://on-ze.com/archives/5127
* --------------------------------------------------------------- */

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 Auto Inseted Codes from WordPress 5.9
* FYI: https://github.com/WordPress/gutenberg/issues/38299
* --------------------------------------------------------------- */

// remove SVG and global styles
remove_action('wp_enqueue_scripts', 'wp_enqueue_global_styles');

// remove wp_footer actions which add's global inline styles
remove_action('wp_footer', 'wp_enqueue_global_styles', 1);

// remove render_block filters which adding unnecessary stuff
remove_filter('render_block', 'wp_render_duotone_support');
remove_filter('render_block', 'wp_restore_group_inner_container');
remove_filter('render_block', 'wp_render_layout_support_flag');

}
add_action('after_setup_theme', 'clean_up_auto_inserted_codes');

?>

今後は、いついかなる時も、たとえ何があっても、決して、一度たりとも、絶対に、私への説明と同意なしに、黙って、コードを挿入することを、究極的に許したくない。

--

--

Takehiko Ono

💻 Web Design and Develop @ aguije inc. / 🏄‍♂️ Pro Web Surfer / ≡ adidas SAMBA / 📸 Fujifilm / 🚲 VanMoofer / 🎮 Nintendo Addict