admin管理员组

文章数量:1327748

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?

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?

Share Improve this question asked Jul 25, 2020 at 17:36 PauloPPauloP 516 bronze badges 8
  • Where's the code with your attempt of what you're trying to do? – mozboz Commented Jul 25, 2020 at 18:22
  • I have another function for that, but it doesn't work.function hello_excerpt_more($more) { global $post; return '... <span class="moretag">[+]</span>'; } add_filter( 'excerpt_more', 'new_excerpt_more' ); – PauloP Commented Jul 26, 2020 at 11:43
  • It's useful to add specifically what you're trying to do and what you've tried to the question. 'It doesn't work' doesn't provide any information about what you actually want the outcome to be. – mozboz Commented Jul 26, 2020 at 13:40
  • I want that after the excerpt, which was customized to show only the first sentence, to have "Read More". – PauloP Commented Jul 26, 2020 at 15:57
  • 1 Do you mean you want this: return $sentence['0'] . $sentence['1'] . "... Read More"; ? – mozboz Commented Jul 26, 2020 at 16:04
 |  Show 3 more comments

1 Answer 1

Reset to default 1

To append strings in PHP use ., like:

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

本文标签: functionsExcerpt – First Sentence amp Read More