説明

基本的な使い方

デフォルトでは文字数110文字で、文末には[...]が付きます。

1

文字数を変更

日本語の環境では公式のやり方での変更はできませんので、標準装備のWP Multibyte Patchプラグインに助けてもらいます。

  1. wp-content/plugins/wp-multibyte-patchの中のwpmp-config-sample.phpをwpmp-config.phpにリネーム。
  2. $wpmp_conf['excerpt_mblength'] = 110;を任意に変更。

この方法と公式の方法を足して、function.phpに以下のコードを追加する方法を自分は使っています。

1
2
3
4
function new_excerpt_mblength($length) {
     return 20;
}
add_filter('excerpt_mblength', 'new_excerpt_mblength');

文末の[...]を変更

デフォルトでは文字数をオーバーした場合の文末に[...]が付与されます。この文字列を変更するにはfunction.phpに以下のコードを追加します。

1
2
3
4
function new_excerpt_more($more) {
    return '.....';
}
add_filter('excerpt_more', 'new_excerpt_more');

文字列をリンクにする
function.phpに以下のコードを追加しますと、「続きを読む」などのリンクに変更できます。

1
2
3
4
function new_excerpt_more($post) {
    return '' . '...続きを読む' . '';   
}   
add_filter('excerpt_more', 'new_excerpt_more');