Skip to content

Instantly share code, notes, and snippets.

@bobbydank
Last active January 30, 2024 21:01
Show Gist options
  • Save bobbydank/0d1bcb07607c068e761b11b7e8195c2f to your computer and use it in GitHub Desktop.
Save bobbydank/0d1bcb07607c068e761b11b7e8195c2f to your computer and use it in GitHub Desktop.
<?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