Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //function.phpに記述
- function get_the_custom_excerpt($content, $length) {
- $length = ($length ? $length : 70);//デフォルトの長さを指定する
- $content = preg_replace('/<!--more-->.+/is',"",$content); //moreタグ以降削除
- $content = strip_shortcodes($content);//ショートコード削除
- $content = strip_tags($content);//タグの除去
- $content = str_replace(" ","",$content);//特殊文字の削除(今回はスペースのみ)
- $content = mb_substr($content,0,$length);//文字列を指定した長さで切り取る
- return $content;
- }
- //表示させたいページのテンプレートに記述
- <?php echo get_the_custom_excerpt( get_the_content(), 50 )."…続きを読む"; ?>
Add Comment
Please, Sign In to add comment