WordPressのpost_typeを指定してビジュアルエディタを無効にする

広告WordPress・PHP を学べる本

Amazonのアソシエイトとして、WordPress functions.phpは適格販売により収入を得ています。

概要説明

記事、固定ページ、カスタム投稿などpost_typeを指定してビジュアルエディタを無効にするカスタマイズ。ライターさんにビジュアルエディタを使ってほしくない、ビジュアルエディタ自体を使用していない場合もこちらで対応が可能です。

post_typeを指定してビジュアルエディタを無効にする

functions.php
/*----------------------------------------------------
 post_typeを指定してビジュアルエディタを無効にする
----------------------------------------------------*/
if ( !function_exists( 'disable_visual_editor' ) ){
    function disable_visual_editor( $wp_rich_edit ) {
        $post_type = get_post_type();

        // 無効にしたい post_type を指定
        $disable_post_type = array('post','page', 'news'); // 投稿,固定ページ,カスタム投稿
        if ( in_array($post_type, $disable_post_type) ) {
            return false;
        } else {
            return $wp_rich_edit;
        }
    }
    add_filter( 'user_can_richedit', 'disable_visual_editor' );
}

WordPress Developer Resources

関連機能

  1. admin_init はログインしていなくても動く:ダッシュボードのウィジェットの保存に、権限と nonce の確かめを足す

  2. WordPress投稿ページにボタンを追加して任意の処理を実行させる

  3. WordPress のリビジョンの数を減らす・止める(wp-config.php と投稿タイプごとの設定・自動保存の間隔)

サイドバー

よく使うカスタマイズ

最近の記事

Profile

PAGE TOP