WordPress the_excerpt() strips html tags, create a custom function to leave them in

go to your theme’s function script:

wp-content/themes/yourthemename/function.php

at the top insert the following (add to ‘<img>’ below to NOT strip out other specific tags, or simply comment the line out…):

function improved_trim_excerpt($text) {
global $post;
if ( ” == $text ) {
$text = get_the_content(”);
$text = apply_filters(‘the_content’, $text);
$text = str_replace(‘]]>’, ‘]]&gt;’, $text);
$text = strip_tags($text, ‘<img>’);
$excerpt_length = 55;
$words = explode(‘ ‘, $text, $excerpt_length + 1);
if (count($words)> $excerpt_length) {
array_pop($words);
array_push($words, ‘[…]’);
$text = implode(‘ ‘, $words);
}
}
return $text;
}
remove_filter(‘get_the_excerpt’,’wp_trim_excerpt’);
add_filter(‘get_the_excerpt’,’improved_trim_excerpt’);

some references: http://codex.wordpress.org/Function_Reference/the_excerpt, http://www.aaronrussell.co.uk/blog/improving-wordpress-the_excerpt/

Leave a Reply

You must be logged in to post a comment.