admin管理员组文章数量:1426001
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 111 Answer
Reset to default 0the_excerpt()
does not recognise or support the <!-- more -->
tag. From the documentation:
The
<!--more-->
quicktag requires templates to usethe_content()
whereas using excerpts requires, and allows, template writers to explicitly choose whether to display full posts (usingthe_content()
) or excerpts (usingthe_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 );
}
?>
本文标签: excerpttheexcerpt() is not trimming at ltmoregt
版权声明:本文标题:excerpt - the_excerpt() is not trimming at <!--more--> 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745395396a2656789.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论