Written by Anonymous
//本文部分の冒頭を綺麗に抜粋する function get_content_excerpt($content, $length = 70){ $content = apply_filters( 'content_excerpt_before', $content); //_v($content); $content = cancel_blog_card_deactivation($content, false); $content = preg_replace('/<!--more-->.+/is', '', $content); //moreタグ以降削除 $content = preg_replace('#<script.*</script>#is', '', $content); //scriptタグ削除 $content = strip_tags($content);//タグの除去 $content = strip_shortcodes($content);//ショートコード削除 $content = str_replace(' ', '', $content);//特殊文字の削除(今回はスペースのみ) $content = preg_replace('/\[.+?\]/i', '', $content); //ショートコードを取り除く $content = preg_replace(URL_REG, '', $content); //URLを取り除く // $content = preg_replace('/\s/iu',"",$content); //余分な空白を削除 //$lengthが整数じゃなかった場合の処理 if (is_int(intval($length))) { $length = intval($length); } else { $length = 70; } $over = intval(mb_strlen($content)) > $length; $content = mb_substr($content, 0, $length);//文字列を指定した長さで切り取る if ( $over && $more = get_entry_card_excerpt_more() ) { $content = $content.$more; } $content = esc_html($content); $content = apply_filters( 'content_excerpt_after', $content); return $content; }