• RSS

[WP]the_excerpt の抜粋文字数と末尾の文字列を変更する方法

  • このエントリーをはてなブックマークに追加
  • follow us in feedly

WordPress のthe_excerpt()で投稿本文を抜粋表示するに当たり、functions.php を編集して表示させる文字数と末尾の文字列を変更する方法のご紹介です。

the_excerpt() の抜粋文字数の変更

文字数を変更するにはWP Multibyte Patch プラグインのフィルターフック「excerpt_mblength」を使うと良いそうです。

ということで、テーマファイル内のfunctions.php を編集して表示文字数を75文字に変更してみます。
function excerpt_length_customize($length) {
     return 75;
}
add_filter('excerpt_length', 'excerpt_length_customize');


the_excerpt() の末尾の文字列の変更

続いて末尾の文字列の変更ですが、こちらもfunctions.php を編集して末尾の[…]の文字を「…続きをみる」に変更してみます。
function excerpt_more_customize($more) {
    return '…続きをみる';
}
add_filter('excerpt_mblength', 'excerpt_more_customize');



  • このエントリーをはてなブックマークに追加
  • follow us in feedly

コメント

コメントを残す