Skip to content

Instantly share code, notes, and snippets.

@smileBeda
Created December 9, 2020 12:36
Show Gist options
  • Save smileBeda/69aa0b7ad1e2728fd234aa2d2a9668e0 to your computer and use it in GitHub Desktop.
Save smileBeda/69aa0b7ad1e2728fd234aa2d2a9668e0 to your computer and use it in GitHub Desktop.
add_filter('get_the_excerpt', 'allow_html_in_excerpt');
function allow_html_in_excerpt($text) { // Fakes an excerpt if needed
global $post;
if ( '' == $text ) {
$text = get_the_content('');
$text = apply_filters('the_content', $text);
$text = str_replace('\]\]\>', ']]>', $text);
/*just add all the tags you want to appear in the excerpt --
be sure there are no white spaces in the string of allowed tags */
$text = strip_tags($text,'<p><br><b><a><em><strong><h1><h2><h3><h4><h5><h6><ol><li>');
/* you can also change the length of the excerpt here, if you want */
$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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment