Site logo

Archived topic

Gutenburg Read More Block — Button/link does does appear

16 replies · Started by Marc on January 2, 2019

Viewing posts 1–15 of 17

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.

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.

Can you guide me to the blog page?

Have you added the PHP snippet?

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

Thanks.

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.

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?

I've forwarded the page in question to Tom to have a look :)

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 :)

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?

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.

Just did, I get the same error.

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

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.

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 :)

This archived topic is closed to new replies.