Archived topic
Custom Excerpt that ignores the MORE tag
9 replies · Started by Jay on September 17, 2020
Hello team,
I was wondering if there's a way to make the excerpt used in the Blog module ignore the MORE tag. I have my category archives setup with the masonry layout, and it works great if the excerpt shows x amount of characters from all posts - but some were written with the MORE tag, at which point the excerpt shows more. Here's an example: https://www.versluis.com/tag/zbrush/
The first post in the list is much longer, and I'd love for it to shortened to 55 characters like the other posts, without having to remove the MORE tag from every post. I'd like to preserve any embedded images though.
I tried crafting a custom excerpt, but had no luck ignoring the MORE tag. Is there a built-in GeneratePress function I can use to make this happen?
Hi there,
This should help:
https://generatepress.com/forums/topic/is-it-possible-to-make-gp-to-ignore-more-tag/#post-875026
Adding PHP: https://docs.generatepress.com/article/adding-php/
Hi Leo, thanks - that did indeed shorten the excerpt, however my images are also stripped out. I'm looking for a way to avoid that in the process.
Unfortunately you cannot have both.
Isn't there a way to take the_content(), count 55 words and spit out the rest, then print that?
Sorry what?
If you use the word count excerpt option in the customizer, then the HTML (images, text decoration etc) are ignored.
I understand that. I'm assuming GeneratePress either serves this via the_content() or the_excerpt() functions. I'm trying to find a way to use whatever comes out of the_content(), ignoring the MORE tag, and shortening that.
Is there a filter I can use after content is presented on archive pages so I can amend it?
GP simply uses the_excerpt() from WordPress for this function:
https://github.com/tomusborne/generatepress/blob/6933da4f9a85e183bcf8485836339043dfc4a650/content.php#L60
https://developer.wordpress.org/reference/functions/the_excerpt/
Maybe it's a better question for the WordPress support team?
Sorry to have troubled you.
Sorry I couldn't be more helpful.
There are 3 ways to handle the excerpt using the_excerpt() function as far as I'm aware of:
- The default word count excerpt method in the customizer which ignores all HTML.
- The excerpt metabox which accepts HTML:
https://www.wpbeginner.com/plugins/how-to-customize-wordpress-excerpts-no-coding-required/
- And the more tag method.
Hope one of these would work for you.