固定ページの場合、HTMLをガッツリ記述した「テキストモード」から「ビジュアルモード」に切り替わると、ソースコードが消えて、レイアウト崩れを起こす場合がある。
そんな時はいっそ固定ページのエディタをビジュアルモードに切り替えれなくしてあげればいい。
以下のコードを「functions.php」に記述。
function disable_visual_editor_in_page() {
global $typenow;
if( $typenow == 'page' ){
add_filter('user_can_richedit', 'disable_visual_editor_filter');
}
}
function disable_visual_editor_filter(){
return false;
}
add_action('load-post.php', 'disable_visual_editor_in_page');
add_action('load-post-new.php', 'disable_visual_editor_in_page');
自分の制作環境では、MW WP FORMのお問い合わせフォームの作成部分もビジュアルエディタは不要なので、「固定ページとMW WP FORMの2つをビジュアルエディタを非表示にするコードは以下
function disable_visual_editor_in_page() {
global $typenow;
if( in_array( $typenow, array( 'page' ,'mw-wp-form' ) ) ){
add_filter('user_can_richedit', 'disable_visual_editor_filter');
}
}
function disable_visual_editor_filter(){
return false;
}
add_action('load-post.php', 'disable_visual_editor_in_page');
add_action('load-post-new.php', 'disable_visual_editor_in_page');