2016/12/20
投稿 カスタム投稿
備忘録です。
投稿記事・固定ページで自動挿入される<p>タグを削除する方法です。
参考サイト
wordpressに自動挿入されるPタグを削除する3つの方法
知らないと恥ずかしい!WordPressでpタグを自動挿入させない方法
functions.pnpに記述
全ての投稿記事・固定ページで<p>タグが削除されます。
remove_filter('the_content', 'wpautop'); remove_filter( 'the_excerpt', 'wpautop' );
投稿テンプレートsingle.php、固定ページのテンプレートpage.phpに記述
個別のテンプレートだけ指定できます。
<?php remove_filter('the_content', 'wpautop'); ?> <?php the_content(); ?>
特定の投稿タイプで<p>タグを削除
functions.pnpに記述
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; }
2023/06/30
神社
御朱印
2023/06/15
Mac
Linux
2023/04/16
時宗
御朱印
2023/04/14
臨済宗
御朱印
2023/04/05
寺院
御朱印