검색시 검색어 하이라이트

functions.php 파일에 추가 해서 검색 단어를 하이라이트 시킬수 있는 팁

get_the_content는 add_filter로 하이라이트 시킬 수 없으니 검색 페이지에서 is_searh인지를 체크 해서 직접 함수 호출 해주는 방식으로 해결 가능

if ( is_search() ) {
    echo highlight_results(wp_trim_words( get_the_content(), 80, '... ' ));
} else {
    echo wp_trim_words( get_the_content(), 80, '... ' );
}
Share this

Leave your question or feedback

따뜻한 말한마디가 블로거를 춤추게 합니다. 이메일 주소는 공개되지 않습니다.