Skip to content

Instantly share code, notes, and snippets.

@topleague
Created September 3, 2017 05:31
Show Gist options
  • Save topleague/13d799f9f780bf4ca02046f7c87bbc03 to your computer and use it in GitHub Desktop.
Save topleague/13d799f9f780bf4ca02046f7c87bbc03 to your computer and use it in GitHub Desktop.
Use HTML Tags in WordPress Excerpts
function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
// remove shortcode
$content = preg_replace("/\/", '', $content);
// short codes are applied
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = strip_tags($content,'
,<b>,<strong>,<a>,<i>,
');
if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
$content = substr($content, 0, $espacio);
$content = $content;
echo "
";
echo $content;
echo "...";
echo "
";
}
else {
echo "
";
echo $content;
echo "
";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment