[Support request] Gutenburg Read More Block — Button/link does does appear

Home Forums Support [Support request] Gutenburg Read More Block — Button/link does does appear

Home Forums Support Gutenburg Read More Block — Button/link does does appear

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #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.

    #771582
    Leo
    Staff
    Customer Support

    Hi 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/

    #771652
    Marc

    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.

    #772120
    Leo
    Staff
    Customer Support

    Can you guide me to the blog page?

    #772161
    Leo
    Staff
    Customer Support

    Have you added the PHP snippet?

    Make sure to reply here. Not through e-mails.

    Thanks.

    #772190
    Marc

    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.

    #772349
    Tom
    Lead Developer
    Lead Developer

    Shouldn’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?

    #772472
    Leo
    Staff
    Customer Support

    I’ve forwarded the page in question to Tom to have a look 🙂

    #772539
    Tom
    Lead Developer
    Lead Developer

    Ah, 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 🙂

    #773356
    Marc

    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_FUNCTION

    I 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?

    #773448
    Leo
    Staff
    Customer Support

    Hmm 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.

    #773493
    Marc

    Just did, I get the same error.

    Is there anything else than this code I need to enter in the Code Snippet?

    #773933
    Tom
    Lead Developer
    Lead Developer

    Hmm, seems to work for me: https://www.screencast.com/t/F9gIzYF8e0z

    Does your function look like the above?

    #774576
    Marc

    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.

    #774624
    Tom
    Lead Developer
    Lead Developer

    Ahh 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 🙂

Viewing 15 posts - 1 through 15 (of 17 total)
  • You must be logged in to reply to this topic.