- This topic has 16 replies, 3 voices, and was last updated 4 years, 4 months ago by
Tom.
-
AuthorPosts
-
January 2, 2019 at 3:01 pm #771513
Marc
When I add a Read More block to a post, I don’t see the read more link or read more button on archive and search results pages. My search in the forums have led me to this article :
https://docs.generatepress.com/article/activating-read-custom-excerpt/
Is this the solution for my current problem? If so, cool… but where and how do I include this snippet of code?
Thank you.
January 2, 2019 at 4:52 pm #771582Leo
StaffCustomer SupportHi there,
Sorry by read more block, do you mean the custom excerpt field?
If so yes you will need one of those PHP functions.
Adding PHP: https://docs.generatepress.com/article/adding-php/
January 2, 2019 at 8:31 pm #771652Marc
It is called the « More » block, under layout elements, in Gutenberg. I tried adding the code snippet I referenced in my original post, using the Code Snippet plugin as you suggested, but it did not work.
Unless you tell me otherwise for GP, I am not using the Excerpt field and do not plan to. I would prefer using Gutenberg’s More block from now on.
January 3, 2019 at 7:23 am #772120Leo
StaffCustomer SupportCan you guide me to the blog page?
January 3, 2019 at 7:50 am #772161Leo
StaffCustomer SupportHave you added the PHP snippet?
Make sure to reply here. Not through e-mails.
Thanks.
January 3, 2019 at 8:14 am #772190Marc
I added the Code Snippet plugin, along with the suggested PHP code in the article I referenced in my first post. It does not make the button appear.
I answered via email because you were asking me the address to our pages index.
January 3, 2019 at 11:07 am #772349Tom
Lead DeveloperLead DeveloperShouldn’t be any need for the snippet if you’re using the more tag. Is there a specific post we can check out that has the more tag?
January 3, 2019 at 1:38 pm #772472Leo
StaffCustomer SupportI’ve forwarded the page in question to Tom to have a look 🙂
January 3, 2019 at 4:08 pm #772539Tom
Lead DeveloperLead DeveloperAh, search results always use the excerpt by default, so they don’t recognize the more tag.
We can change that with a filter like this:
add_filter( 'generate_show_excerpt', function( $show ) { if ( is_search() ) { global $post; $more_tag = apply_filters( 'generate_more_tag', strpos( $post->post_content, '<!--more-->' ) ); if ( $more_tag ) { $show = false; } } return $show; } );
Let me know if that does the trick or not 🙂
January 4, 2019 at 2:13 pm #773356Marc
Hi, Tom.
Thank you for your suggested filter. Bear with me if I am not doing the right thing, but I created a code snippet like I had done with the other filter, but I got the following error message when I saved and activated the snippet :
The snippet has been deactivated due to an error on line 1:
syntax error, unexpected T_FUNCTIONI tried ignoring the error and activate the filter nevertheless, but it doesn’t work. When I search ‘412’ on our site, I get the list of courses and those that use a ‘More’ tag don’t have a ‘Read More’ button (Lire la suite, in our case).
Is there an error in the suggested filter, or did I do something wrong?
January 4, 2019 at 5:17 pm #773448Leo
StaffCustomer SupportHmm can you double check that the whole code is copied and this is the only function in that snippet?
I just tested the code using Code Snippets as well and didn’t get an error.
January 4, 2019 at 7:51 pm #773493Marc
Just did, I get the same error.
Is there anything else than this code I need to enter in the Code Snippet?
January 5, 2019 at 9:28 am #773933Tom
Lead DeveloperLead DeveloperHmm, seems to work for me: https://www.screencast.com/t/F9gIzYF8e0z
Does your function look like the above?
January 6, 2019 at 8:15 am #774576Marc
I checked and the code I have in Code Snippet is identical to your screen capture. I copied and pasted it from your previous post here. I tried desactivating two page builders I have that I want to get rid of, hoping they might be causing a conflict. It doesn’t change, when I search ‘412’ on the site, the courses are displayed but those where I use the More block in Gutenberg do not have a ‘Lire la suite’ button as they should.
January 6, 2019 at 9:26 am #774624Tom
Lead DeveloperLead DeveloperAhh I think I know what’s wrong. You’re using a super old version of PHP.
Contact your hosting and ask them to update you to PHP 7. It will fix this issue and will make your site a lot faster/more secure 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.