WPのエディタでコーディングしたいときにネックになるのが自動挿入されるタグ。
親切心がアダになってますよ!
そんな時はfunctions.phpに下記ソースを入れるだけ。
1 2 |
remove_filter('the_content', 'wpautop'); // 記事の自動整形を無効にする remove_filter('the_excerpt', 'wpautop'); // 抜粋の自動整形を無効にする |
スポンサーリンク
投稿ページのみに適用
1 2 3 4 5 6 7 8 9 10 11 12 13 |
add_filter('the_content', 'wpautop_filter', 9); function wpautop_filter($content) { global $post; $remove_filter = false; $arr_types = array('post'); //適用させる投稿タイプを指定 $post_type = get_post_type( $post->ID ); if (in_array($post_type, $arr_types)) $remove_filter = true; if ( $remove_filter ) { remove_filter('the_content', 'wpautop'); remove_filter('the_excerpt', 'wpautop'); } return $content; } |
固定ページにのみ適用
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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 ( $remove_filter ) { remove_filter('the_content', 'wpautop'); remove_filter('the_excerpt', 'wpautop'); } return $content; } |
カスタム投稿にのみ適用
1 2 3 4 5 6 7 8 9 10 11 12 13 |
add_filter('the_content', 'wpautop_filter', 9); function wpautop_filter($content) { global $post; $remove_filter = false; $arr_types = array('★カスタム投稿タイプをここに入力★'); //適用させる投稿タイプを指定 $post_type = get_post_type( $post->ID ); if (in_array($post_type, $arr_types)) $remove_filter = true; if ( $remove_filter ) { remove_filter('the_content', 'wpautop'); remove_filter('the_excerpt', 'wpautop'); } return $content; } |
他にもありますが疲れたのでまたの機会に。