Excerpt – First Sentence & Read More

I am using this function to limit the excerpt to the first sentence…

function hello_first_sentence( $string ) {
 
    $sentence = preg_split( '/(.|!|?)s/', $string, 2, PREG_SPLIT_DELIM_CAPTURE );
    return $sentence['0'] . $sentence['1'];
 
} add_filter( 'get_the_excerpt', 'hello_first_sentence', 10, 1 );

However, for some reason, I am unable to add the “read more” after the excerpt… any help?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

To append strings in PHP use ., like:

return $sentence['0'] . $sentence['1'] . "... Read More";


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x