[wp-trac] [WordPress Trac] #39921: the_excerpt needs additional parameters to control teaser length and visibility of 'read more' link
WordPress Trac
noreply at wordpress.org
Tue Feb 21 13:36:42 UTC 2017
#39921: the_excerpt needs additional parameters to control teaser length and
visibility of 'read more' link
-------------------------------+------------------------------
Reporter: subrataemfluence | Owner:
Type: enhancement | Status: reopened
Priority: normal | Milestone: Awaiting Review
Component: Posts, Post Types | Version: 4.7.2
Severity: normal | Resolution:
Keywords: close | Focuses: template
-------------------------------+------------------------------
Comment (by subrataemfluence):
Thank you! https://codex.wordpress.org/Conditional_Tags is a very useful
area to explore.
Meanwhile I added the following function in functions.php which actually
works, although probably this is not the correct way to go!
{{{
function get_excerpt($limit, $show_more = true) {
$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($show_more)
return $excerpt . '<a href="'.get_the_permalink().'"
rel="nofollow"> [more]</a>';
else
return $excerpt;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39921#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list