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

posts - How to limit wordpress the_excerpt() dynamically

programmeradmin5浏览0评论

I'm trying to limit WordPress post excerpt and I've tried some ways to do it but all of them was not the stuff that I need, to say concisely I want to limit post excerpt with a number that I use everywhere with differences.

For example, I need to make something I use it like this: <?php the_excerpt('30') ?> with this part of the code, I wanna limit my excerpt to 30 chars and in another place, I wanna use a different value like: <?php the_excerpt('150') ?> Is it in WordPress?

I'm trying to limit WordPress post excerpt and I've tried some ways to do it but all of them was not the stuff that I need, to say concisely I want to limit post excerpt with a number that I use everywhere with differences.

For example, I need to make something I use it like this: <?php the_excerpt('30') ?> with this part of the code, I wanna limit my excerpt to 30 chars and in another place, I wanna use a different value like: <?php the_excerpt('150') ?> Is it in WordPress?

Share Improve this question asked Oct 2, 2020 at 20:44 irgfxirgfx 101
Add a comment  | 

1 Answer 1

Reset to default 0

according to the documentation, it is more correct to change the length of the excerpt using add_filter:

add_filter( 'excerpt_length', function(){
    return 10;
});

you can make your own function based on this, like this:

add_filter( 'excerpt_length', 'new_excerpt', 10, 1);
function new_excerpt( $lenth ){
    return $length;
});

...

apply_filters( 'excerpt_length', 150 );
发布评论

评论列表(0)

  1. 暂无评论