WP PHP

意図しない崩れの防止に!WordPressのエディタを正しく設定

WordPressの投稿にはビジュアルエディタがついています。
HTMLがわからない人でも記事を投稿するのに便利なのですが、、、よく崩れます!

HTMLタグでレイアウトを組んだページをビジュアルエディタで編集しようとすると、タグが消える(怒)。
また、ありがた迷惑?のオートPによって、pタグに付けたstyleが意図せず効いてしまう。

これらが起こらないようにするために、そもそもの設計で、ビジュアルエディタを使用できるのは「お知らせ」や「ブログ」などのシンプルな記事に限定しておきます。

崩れてもらっては困る「固定ページ」のレイアウト。
そもそも、固定ページではビジュアルエディタは使わない。表示を消す。

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' );

オートPをさせないコンテンツ読み込み記述

<?php the_content(); ?>

のかわりに

<?php
remove_filter('the_content', 'wpautop');
the_content();
add_filter('the_content', 'wpautop'); 
?>

を使う。

home > TIPS > WP PHP > 意図しない崩れの防止に!WordPressのエディタを正しく設定

Copyright © 2012 SMILEWORKS All Rights Reserved.