Last active
January 30, 2024 21:01
-
-
Save bobbydank/0d1bcb07607c068e761b11b7e8195c2f to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
/** | |
* Filter the except length to any specified length of words. | |
* | |
* @param string $content the content | |
* @param int $length Excerpt length. | |
* @return int (Maybe) modified excerpt length. | |
*/ | |
function catchy_labs_custom_excerpt($content, $limit) { | |
$excerpt_no_shortcodes = strip_shortcodes($raw_excerpt); | |
$excerpt = explode(' ', strip_tags($excerpt_no_shortcodes), $limit); | |
if (count($excerpt)>=$limit) { | |
array_pop($excerpt); | |
$excerpt = implode(" ",$excerpt).' [...]'; | |
} else { | |
$excerpt = implode(" ",$excerpt); | |
} | |
$excerpt = preg_replace('`[[^]]*]`','',$excerpt); | |
return $excerpt; | |
} | |
?> | |
<div class="the-excerpt"> | |
<p><?php echo catchy_labs_custom_excerpt( get_the_content(), 45 ); ?></p> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment