wp_excerpt()で挿入される抜粋の[…]を「続きを読む」にカスタマイズ

WordPress2.9以上では、Excerptの後の[…]を編集するためのフックが追加されたようです。
カスタマイズしたい方は、functions.phpに以下の関数を追加してください。

function new_excerpt_more($excerpt) {
	return str_replace('[...]', '...', $excerpt);
}
add_filter('wp_3_trim_excerpt', 'new_excerpt_more');

例えば、[…]じゃなくて、<more>を挟んだときのように「続きを読む」リンクにしたい場合は、次のように書きます。

function new_excerpt_more($post) {
        return '<div><a href="'. get_permalink($post->ID) . '">' . '続きを読む...' . '</a></div>'; 
}
add_filter('excerpt_more', 'new_excerpt_more');

広告

これで大分使いやすくなりますね。

Plugin API/Filter Reference/excerpt more « WordPress Codex
(日本語翻訳ドキュメントは未だありません。2010/11/26(金)現在。)

About: dacelo


11 thoughts on “wp_excerpt()で挿入される抜粋の[…]を「続きを読む」にカスタマイズ”

  1. Pingback: 宮本
  2. Pingback: dacelo

Leave a Reply to webprofile Cancel reply

Your email address will not be published. Required fields are marked *