Created
June 12, 2020 17:39
-
-
Save mfyz/87c6e3bd2bae65158eb47e5a962aeb44 to your computer and use it in GitHub Desktop.
wordpress custom excerpt
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
<? | |
function new_excerpt_more( $more ) { return '...'; } | |
add_filter('excerpt_more', 'new_excerpt_more'); | |
$content = get_the_excerpt(); | |
if (!$content) { | |
$content = get_the_content(); | |
if (strlen($content) > 150) { | |
$content = wp_strip_all_tags($content); | |
$content = substr($content, 0, 150); | |
$content = explode(' ', $content); | |
if (count($content) > 1) { | |
array_pop($content); | |
} | |
$content = implode(' ', $content); | |
$content .= "..."; | |
} | |
} | |
print $content; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment