最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Excerpt – First Sentence & Read More

programmeradmin7浏览0评论

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";
发布评论

评论列表(0)

  1. 暂无评论