WordPress」タグアーカイブ

WordPressの自動 <p>タグ 挿入機能を無効にする

WordPressを使っていると、勝手に<p>タグが挿入されることがある。
いままでは面倒なので無視していたが、我慢ならないところに挿入されて、周辺の文章を書き換えたりしたのだがどうにも直らないので調べてみた。

方法には二つあるようだ

1.wp-includes/default-filters.php の wpautop の関連する行をコメントアウトする

wp-includes/default-filters.php の該当は以下の3行

add_filter(’the_content’, ‘wpautop’);
add_filter(’the_excerpt’, ‘wpautop’);
add_filter( ‘comment_text’, ‘wpautop’, 30 );

このうち今回問題が発生している the_content のところだけコメントアウトした。

// add_filter(’the_content’, ‘wpautop’);

余計なところを直して、新たな問題が発生しないとも限らないからだ。
問題がないところはいじらないに限る。

参考サイト)
http://www.devolen.com/blog/wp_custum/ptag_out/
http://msweb.moo.jp/wordpress/202/
他多数

2. remove_filter() を追加する

全体に<p>タグ自動挿入を無効にするには、
wp-includes/functions.php に

remove_filter(‘the_content’, ‘wpautop’);

を一行追加する。

あるいは、特定の場所だけ無効にしたいとき、たとえばトップページだけ無効にしたいときはindex.php の the_content のループの前に追加する。

remove_filter(‘the_content’, ‘wpautop’);

the_content();

 

参考サイト)

http://www.webopixel.net/wordpress/171.html
http://www.webtipsbox.com/wordpress-setting.html
http://rayuela.kr/jp/wordpress/post548/

他多数