Cocoonは、カスタムフィールドに16の値と投稿画面に10のボックスを追加しますが、完全に無効にする方法を紹介します。バージョン: 1.5.1.1で動作確認済みです。
概要
Cocoonは、投稿の編集画面において次の機能が追加されます(順不同)。
- SEO設定
- カスタムCSS
- カスタムJavaScript
- 広告設定
- ページ設定
- 更新日の変更
- リダイレクト
- AMP設定
- メモ
- SNS画像
そして、設定を保存するために次のカスタムフィールドの値を追加します。
'update_level'
'the_page_toc_novisible'
'page_type'
'the_page_seo_title'
'the_page_meta_description'
'the_page_meta_keywords'
'the_page_noindex'
'the_page_nofollow'
'the_page_no_amp'
'the_page_memo'
'the_page_ads_novisible'
'is_ads_removed_in_page'
'sns_image_url'
'redirect_url'
'_custom_js'
'_custom_css'
なんだか気になる…
設定の有無に関わらず、保存時にすべての記事・固定ページなどにおいて追加されます。他にカスタムフィールドを用いた運用をしている際、目障りに感じることがあります。また、もし今後他のテーマに切り替える事になった際に、設定したものがすべて無意味になってしまいます。
無効にする方法
次のコードを子テーマのfunctions.phpに追加します。このコードを追加してから、ボックスは消え、記事を投稿、更新しても値が追加されることはありませんが、既に存在する場合でも削除されません。
<?php /* 更新日の変更 'update_level' */ function add_update_custom_box(){}; /* ページ設定 'the_page_toc_novisible' 'page_type' */ function add_page_custom_box(){}; function page_custom_box_save_data(){}; /* SEO設定 'the_page_seo_title' 'the_page_meta_description' 'the_page_meta_keywords' 'the_page_noindex' 'the_page_nofollow' */ function add_seo_custom_box(){}; function seo_settings_admin_script(){}; function seo_custom_box_save_data(){}; /* AMP設定 'the_page_no_amp' */ function add_amp_custom_box(){}; function amp_custom_box_save_data(){}; /* メモ 'the_page_memo' */ function add_memo_custom_box(){}; function memo_custom_box_save_data(){}; /* 広告設定 'the_page_ads_novisible' 'is_ads_removed_in_page' */ function add_ad_custom_box(){}; function ad_custom_box_save_data(){}; /* SNS画像 'sns_image_url' */ function add_sns_image_custom_box(){}; function sns_image_custom_box_save_data(){}; /* リダイレクト 'redirect_url' */ function add_redirect_custom_box(){}; function redirect_custom_box_save_data(){}; /* カスタムCSS '_custom_css' */ function add_custom_css_custom_box(){}; function custom_css_custom_box_save_data(){}; /* カスタムJavaScript '_custom_js' */ function add_custom_js_custom_box(){}; function custom_js_custom_box_save_data($post_id){}; ?>
結果
記載したコードすべて適用した場合の結果です。
表示項目
ビフォー
アフター
カスタムフィールド
アフター
すでに追加されたカスタムフィールドを削除する方法
直接データベース(_postmetaテーブル)で削除することも可能ですが、Delete Custom Fieldsプラグインを使用すると簡単です。ただし、かなり昔のプラグインなので、脆弱性がある可能性があります。使い終わったらすぐに削除しておきましょう。
コメント