the_excerpt(抜粋・概要)タグでpタグを除外する方法。 Comment

12:27 AM on 2010年11月15日

抜粋欄に記入されている内容(記入されていない場合は本文最初の数文字)を表示するthe_excerptタグですが、大変親切な事に勝手にpタグを入れてくれます。

と、なると、抜粋を表示してそこにパーマリンクを指定しようとするとpタグの外にaタグになるのでhtml上よろしくなかったり、metaのdescriptionに使いたいのに中にpタグが入るなんて事になってしまうので、都合が悪いです。

調べたところこちらのサイトで紹介されていました。

function.phpに

1
2
3
4
<?php
    // pタグ自動挿入解除
    remove_filter('the_excerpt', 'wpautop');
?>

を追加すれば解除できます。

ちなみにwp-includes/default-filters.phpを触る方法もありますが、こちらはWordPress本体のアップデートで上書きされてしまうのでお勧めしません。

Leave a Reply

Have something to say? Jump right in!     Formatting

(required)
(required)

Close

Formatting Your Comment

The following XHTML tags are available for use:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

URLs that start with http:// are automatically converted to hyperlinks.