excerpt - the_excerpt() is not trimming at <!--more-->

I am using the following code:<?php the_excerpt(); ?>This trims after 50 ish words, way after the <!--more-->

I am using the following code:

    <?php the_excerpt(); ?>

This trims after 50 ish words, way after the <!--more--> I added in the post's source.

This, instead, correctly trims out the part before <!--more--> as expected.

    <?php the_content("", TRUE); ?>

How do I change the_excerpt() so that it returns the part before <!--more-->?

I tried using get_extended() but it does not produce the same output as the_excerpt(); specifically, it does not add <p> tags, and probably something else.

Thank you in advance.

I am using the following code:

    <?php the_excerpt(); ?>

This trims after 50 ish words, way after the <!--more--> I added in the post's source.

This, instead, correctly trims out the part before <!--more--> as expected.

    <?php the_content("", TRUE); ?>

How do I change the_excerpt() so that it returns the part before <!--more-->?

I tried using get_extended() but it does not produce the same output as the_excerpt(); specifically, it does not add <p> tags, and probably something else.

Thank you in advance.

Share Improve this question asked Jun 17, 2019 at 7:52 WesAtWorkWesAtWork 11
Add a comment  | 

1 Answer 1

Reset to default 0

the_excerpt() does not recognise or support the <!-- more --> tag. From the documentation:

The <!--more--> quicktag requires templates to use the_content() whereas using excerpts requires, and allows, template writers to explicitly choose whether to display full posts (using the_content()) or excerpts (using the_excerpt()).

The point is that the_excerpt() allows theme authors (you) to require an excerpt. This is automatically created by trimming the content, but if the user needs a specific excerpt then they can enter a manual excerpt. Either way they cannot accidentally display the full post content.

On the other hand the_content() lets the user decide whether or not to use an excerpt. If they do want one, then they use the <!-- more --> tag. If they don't, then they leave it out and the full post will be displayed.

As a theme author you need to decide which you should support. If displaying the full content of the post would break your layout, then you should use the_excerpt(), but if the theme would look fine either way, then use the_content().

If you want the user to decide between these options then you could create a Customiser setting that let's the user choose. Then in your templates you could check this value and use the appropriate tag:

<?php
if ( 'excerpt' === get_theme_mod( 'setting_name_here' ) ) {
    the_excerpt();
} else {
    the_content( '', true );
}
?>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745395396a4625853.html

相关推荐

  • excerpt - the_excerpt() is not trimming at &lt;!--more--&gt;

    I am using the following code:<?php the_excerpt(); ?>This trims after 50 ish words, way after the <!--more-->

    12小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信