2013-02-25 5 views
1

내가 테마에서 발췌를 표시하는 코드 줄을 (코드가) :제거 단축 코드

나는 발췌에서 단축 코드를 제거하려면이 코드를 삽입하려면 어떻게
<p class="desc"><?php echo mb_strimwidth(strip_tags(get_the_content('')), 0, 220, '...'); ?></p> 

?

$text = preg_replace('|\[(.+?)\](.+?\[/\\1\])?|s', '', $text); 

저는 PHP를 자르려고하고 있습니다. 저는이 문제에 대한 도움이 조금 필요합니다.

감사합니다.

답변

3

휠을 다시 발명하는 대신 코어 워드 프레스 기능 strip_shortcodes()을 사용하는 것이 좋습니다.

<p class="desc"><?php echo mb_strimwidth(strip_shortcodes(strip_tags(get_the_content(''))), 0, 220, '...'); ?></p> 
0

이 경우 DONT USE REGEX!

REGEX 예를 들어, 발췌에서 자신의 노트를 제거합니다 : 사용 등록 된 단축 코드를 탐지하고 제거 내장 함수 strip_shortcodes, 그래서
Hello, on May 27 [1995] , blabla

더 나은 :

add_filter('the_excerpt','myRemoveFunc'); function myRemoveFunc(){ 
    return mb_strimwidth(strip_shortcodes(get_the_content()), 0, 220, '...'); 
}