admin管理员组

文章数量:1287942

I've been looking for an answer to this question for a long time, but haven't found anything: how come when I use the_excerpt() on a given site it doesn't automatically print the first few characters of the content?

The excerpt only prints it if something has been added to the WordPress summary field of the post.

How can I fix this problem? With other sites this does not happen and if no text is added on the summary the excerpt is generated automatically.

What could it be that the excerpt is not automatically generated?

My situation is similar to this: Automatic Excerpt Not Working

but your response did not provide me with any advice unfortunately.

I've been looking for an answer to this question for a long time, but haven't found anything: how come when I use the_excerpt() on a given site it doesn't automatically print the first few characters of the content?

The excerpt only prints it if something has been added to the WordPress summary field of the post.

How can I fix this problem? With other sites this does not happen and if no text is added on the summary the excerpt is generated automatically.

What could it be that the excerpt is not automatically generated?

My situation is similar to this: Automatic Excerpt Not Working

but your response did not provide me with any advice unfortunately.

Share Improve this question asked Oct 14, 2021 at 7:20 Matteo FeduziMatteo Feduzi 299 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

By default, the_excerpt(), doesn't uses the post/page content wysiwyg, it has its own textarea, that by default is not visible, you need to enable it first via screen options.

After you checked this checkbox you can scroll down to the bottom of the post/page and see a new textarea, this is the excerpt.

If you want to use the content (wysiwyg, the_conetnt() or get_the_content()) as excerpt, you will need to use wp_trim_words.
Something like this.

// the second argument is how many words to trim, default is 55
<?= wp_trim_words(get_the_content(), 30); ?>

Anothe option, if you want to keep the html structure would be to do this.

<?= force_balance_tags(html_entity_decode(wp_trim_words(htmlentities(wpautop(get_the_content())), 30))); ?>

本文标签: phpAutomatic excerpt is not shown with theexcerpt() command