LoginSignup
0
0

More than 3 years have passed since last update.

【wordpress】勝手にpタグ入れないタグ テンプレ

Last updated at Posted at 2021-05-18

タイトルそのまま わかる方向けコピペセット

一括設定

funciton.phpに下記記述

add_action('init', function() {
remove_filter('the_excerpt', 'wpautop');
remove_filter('the_content', 'wpautop');
});
add_filter('tiny_mce_before_init', function($init) {
$init['wpautop'] = false;
$init[‘apply_source_formatting’] = true;
return $init;
});

個別設定

<?php the_content(); ?>の前に下記記述

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

特定の投稿タイプで設定

add_filter('the_content', 'wpautop_filter', 9);
function wpautop_filter($content) {
global $post;
$remove_filter = false;

//各自設定してね ここから
//特定のカスタム投稿のみ
$arr_types = array('★カスタム投稿タイプ名');
//複数の投稿タイプの場合
$arr_types = array('page','XXX','XXX');
//固定ページのみ
$arr_types = array('page');
//記事ページのみ
$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;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0