On the WordPress archive template I am using a custom excerpt function that includes a reference to strip_shortcodes()
. For some reason, shortcodes are being rendered and displayed in the archive.
Example: http://arisehub.org/blog/page/2/
Scroll down to “Sing a New Song with Joshua Cunningham”
Notice the script code showing up. That’s a shortcode reference to JW Player, showing up rendered.
Here’s the code I’m using for the custom excerpt function.
function custom_excerpt($length, $more_text) {
global $post;
$text = get_the_content();
$text = strip_shortcodes( $text );
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text, '<a>, <p>, <strong>, <em>, <b>');
if(!empty($length)){
$excerpt_length = apply_filters('excerpt_length', $length);
} else {
$excerpt_length = apply_filters('excerpt_length', 180);
}
if(!empty($more_text)){
$excerpt_more = apply_filters('excerpt_more', ' ' . '… <br /><a href="'.get_permalink($post->id).'" class="more-link">'.$more_text.'</a>');
} else {
$excerpt_more = apply_filters('excerpt_more', ' ' . '…<a href="'.get_permalink($post->id).'" class="more-link">+ more</a>');
}
$words = preg_split('/(<a.*?a>)|\n|\r|\t|\s/', $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE );
if ( count($words) > $excerpt_length ) {
array_pop($words);
$text = implode(' ', $words);
$text = $text . $excerpt_more;
} else {
$text = implode(' ', $words);
}
$output="<p>".$text.'</p>';
echo $output;
}
Any ideas?