LoginSignup
2

More than 5 years have passed since last update.

wordpressの「抜粋」に<br>を入れる

Posted at

wordpressには記事の抜粋テキストを任意に設定できるようになっている。
出力の際にはget_the_excerpt()関数又はthe_excerpt()で出力できるが、内部で改行を行うことが出来ない。

brタグを直接抜粋の欄に入力すれば機能するが、そういったことも面倒くさい場合はget_the_excerpt()関数の改行をbrタグに変換する関数を追加する。

functions.php
function get_the_excerpt_with_br($post) {
    global $post;
    $excerpt_with_br = get_the_excerpt($post->ID);
return nl2br($excerpt_with_br);
}

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2