Last active
February 21, 2021 08:19
-
-
Save developer-anuragsingh/14cfb9e4f69219745539de872b6ade7b to your computer and use it in GitHub Desktop.
WP - Get 'excerpt' with HTML tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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