Last active
November 28, 2021 17:28
-
-
Save dcooney/e0f0b3af88c43edcca9c581b6178ae35 to your computer and use it in GitHub Desktop.
Custom Excerpt
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 | |
// Get custom excerpt | |
function alm_get_excerpt($limit = 40, $after = null) { | |
$excerpt = explode(' ', get_the_excerpt(), $limit); | |
if (count($excerpt)>=$limit) { | |
array_pop($excerpt); | |
$excerpt = implode(" ",$excerpt).'...'; | |
} else { | |
$excerpt = implode(" ",$excerpt); | |
} | |
$excerpt = preg_replace('`[[^]]*]`','',$excerpt); | |
if($after) | |
$excerpt = $excerpt . $after; | |
if($excerpt) | |
echo '<p>'.$excerpt.'</p>'; | |
} | |
// alm_get_excerpt(30); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment