
WordPressの非常に便利な機能が自動pタグ挿入機能。開始時にpタグ入れて、改行すると自動でpタグを閉じてくれるやつです。
ただ、ときにこの機能が邪魔な時もありますよね。
そんなときは、クライアントが運用中に入力していく投稿ページにはpタグ自動挿入機能を残して、
固定ページだけ機能を動かないようにするといいです。
テーマのfunctions.phpに下記を記述。
add_filter('the_content', 'wpautop_filter', 9);
function wpautop_filter($content) {
global $post;
$remove_filter = false;
//自動整形を無効にする投稿タイプを記述 =固定ページ
$arr_types = array('page');
$post_type = get_post_type( $post->ID );
if (in_array($post_type, $arr_types)){
$remove_filter = true;
}
//投稿ページ以外の自動整形を無効にしたければ
if (!is_single()){
$remove_filter = true;
}
// 特定のページの自動整形を無効にしたければ*****にページIDを入れる
if (get_the_ID() == *****){
$remove_filter = true;
}
if ( $remove_filter ) {
remove_filter('the_content', 'wpautop');
remove_filter('the_excerpt', 'wpautop');
}
return $content;
}
WordPressカスタマイズ事例やウェブ制作ノウハウの新着情報、お役立ち情報を
リアルタイムにメルマガ配信!