워드프레스 요약문(Excerpt)에서 숏코드 제거하기

본문에 숏코드를 추가했더니 요약글(Excerpt)에 숏코드가 텍스트 형태로 그대로 노출되네요.
Shortcode in WordPress Excerpts
숏코드를 없애려면 strip_shortcodes() 함수를 사용하면 됩니다(여기 참고).

Example 1:

<?php echo mb_strimwidth(strip_shortcodes(strip_tags(get_the_content(''))), 0, 220, '...'); ?>

Example 2(요약문 길이 변경 함수):

function custom_length_excerpt($word_count_limit) {
$content = wp_strip_all_tags(get_the_content() , true );
echo wp_trim_words(strip_shortcodes($content), $word_count_limit) . ' <a class="read-more" href="' . get_permalink( get_the_ID() ) . '"> Read More </a>';
}
일부 글에 제휴 링크가 포함될 수 있으며 파트너스 활동으로 일정액의 수수료를 받을 수 있습니다.

댓글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다