Skip to content

Instantly share code, notes, and snippets.

@developer-anuragsingh
Last active February 21, 2021 08:19
Show Gist options
  • Save developer-anuragsingh/14cfb9e4f69219745539de872b6ade7b to your computer and use it in GitHub Desktop.
Save developer-anuragsingh/14cfb9e4f69219745539de872b6ade7b to your computer and use it in GitHub Desktop.
WP - Get 'excerpt' with HTML tags
/**
* Return post's excerpt without removing HTML tags
*
* @param int $count total content length to be return
*
* @return string
*/
function Get_As_excerpt($count = 150)
{
if (has_excerpt()) {
$excerpt = get_the_excerpt();
} else {
$excerpt = get_the_content();
}
$excerpt = substr($excerpt, 0, $count);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = apply_filters('the_excerpt', $excerpt . '...');
return $excerpt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment