- This topic has 12 replies, 5 voices, and was last updated 5 years, 11 months ago by Leo.
-
AuthorPosts
-
May 9, 2018 at 6:06 am #571381Piotr
Hey,
I have been using GP for about a week now and am very happy with it in general.
However, there is one thing that bothers me which is the priority of excerpts.
So: I start with setting the [Layout] => [Blog] => [Content] => [Archives] => [Content type] option to “Excerpt” (I want to see excerpts of posts on the home page).
Then:
* If there is no <—more–> tag in a post but the [Excerpt] field is filled in, everything works as expected i.e. the excerpt is being loaded from the [Excerpt] field and displayed in the archive.
* If there is no excerpt at all anywhere (i.e. [Excerpt] field is blank and also no <–more–> tag) then everything works fine as well i.e. GP automatically extracts a pre-defined number of words from the post and displays it as the excerpt. Grand.However (this is where I see an issue):
* If a post has the <–more–> tag in it, the blog archive page ignores the Excerpt field.To my understanding, this should work the other way around. All other themes I used (both free and paid) have this done correctly i.e. they prioritize the [Excerpt] field over the <–more–> tag content. The understanding here is that if the author of the entry made that extra effort to fill-in the [Excerpt] field, it is important and should not be ignored.
Is there anything I can do to get this working in GP?
May 9, 2018 at 8:06 am #571541DavidStaffCustomer SupportHi Piotr,
This is one for Tom, ill get him to advise.
David
May 9, 2018 at 8:50 am #571587TomLead DeveloperLead DeveloperIf the tag is used, we need to use
the_content()
function to output the content, and cut it off at the tag. That’s what allows it to use HTML.For the excerpt metabox to work, we need to use
the_excerpt()
function to output the content.Changing this directly in the theme would likely make some people pretty angry, as it’s been working this way for years.
However, we can adjust it to do what we need with a filter:
add_filter( 'generate_show_excerpt', 'tu_force_excerpt_field' ); function tu_force_excerpt_field( $excerpt ) { if ( has_excerpt() ) { return true; } return $excerpt; }
Let me know if that works or not π
May 9, 2018 at 9:51 am #571634PiotrYes, it works straight away, kudos for prompt reply!
Now, two bits of advice:
1.
“Changing this directly in the theme would likely make some people pretty angry, as itβs been working this way for years.”
Buddhists change their sacred books after 3000 years if they discover that the books are incorrect. If things can be fixed, they should be fixed.
2.
If you don’t want to make your users jumping up and down (which I fully understand) just add an option in theme UI for controlling the priority of the <more> tag and the excerpt. This will make more users happy while keeping the other users equally happy π
Thanks again for sorting the issue!
May 9, 2018 at 8:32 pm #571988TomLead DeveloperLead DeveloperNo problem! I’ll definitely keep this in mind π
May 19, 2018 at 8:20 am #579540Matthias HeilThis is exactly what I’m looking for. Where exactly do I paste the code? Probably in one of the hooks fields?
May 19, 2018 at 9:17 am #579582LeoStaffCustomer SupportOne of these methods: https://docs.generatepress.com/article/adding-php/
Code snippet is the easiest if you aren’t using a child theme.
May 19, 2018 at 12:08 pm #579679Matthias HeilThanks ever so much, works like a charm!-)
Edit: Is there a way of adding a “read more” tag in manual abstracts/extracts? – See https://matthiasheil.de/category/religion/ for an archive with posts that both have and have no such button…
May 19, 2018 at 3:05 pm #579748LeoStaffCustomer SupportMay 19, 2018 at 11:44 pm #579863Matthias HeilCheers! Excellent!! Have a great Whitsun!!!-)
May 20, 2018 at 9:23 am #580161LeoStaffCustomer SupportNo problem!
May 20, 2018 at 10:02 am #580183PiotrJust to add my five cents, while the method of adding the “Read more” button to posts with manual excerpts works correctly, it does not take translations into account i.e. if you switch your WordPress UI to another language, you also need to remember to update that “tu_excerpt_metabox_more” function as well.
Not a big deal, just something to be aware of.
May 20, 2018 at 11:31 am #580223LeoStaffCustomer SupportThanks for the inputs π
-
AuthorPosts
- You must be logged in to reply to this topic.