Black Friday Sale! Get up to $40 off GP Premium!Learn more

[Resolved] Read more-button disappears when using "manual" excerpts

Home Forums Support Read more-button disappears when using "manual" excerpts

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #476389
    Cecilia

    I wrote a curated excerpt for a blog post. This makes the Read More-button disappear for that post on the archive page.

    Any tip on how to make that button visible again?

    The settings in the customizer are:
    Excerpt
    20 words
    Show as button

    The automatic excerpt is fine, but for some posts I want to use the curated version that I have written for that blog post.

    GeneratePress 2.0.2
    GP Premium 1.5.6
    #476456
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    WordPress doesn’t display a read more button when the manual excerpt is used unfortuntely.

    However, we can force it to like this:

    add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' );
    function tu_excerpt_metabox_more( $excerpt ) {
    	$output = $excerpt;
    	
    	if ( has_excerpt() ) {
    		$output = sprintf( '%1$s <p class="read-more-container"><a class="button" href="%2$s">Read more</a></p>',
    			$excerpt,
    			get_permalink()
    		);
    	}
    	
    	return $output;
    }

    Let me know if you need more info ๐Ÿ™‚

    #476488
    Cecilia

    Worked like clockwork! I just copied the code you sent into my child theme’s functions.php, saved and – voilรก!

    Thank you!
    <3

    /Cecilia

    #476752
    Tom
    Lead Developer
    Lead Developer
    #1344105
    Joseph

    Hey Tom,
    Thanks for sharing the code.
    I am clueless on the tech stuff and only just started my blog. Where do I add the code to get the read button for my post?
    Thanks
    Joe

    #1344350
    David
    Staff
    Customer Support

    Hi there,

    the code is PHP – this article explains:

    https://docs.generatepress.com/article/adding-php/

    And for reference here is an article relating to this topic:

    https://docs.generatepress.com/article/activating-read-custom-excerpt/

    #1344701
    Mike

    Hi Tom,

    I used this too – so thanks! I made a couple of changes to suit what I used it for:

    1) changed the class to match the read more button in the theme (i noticed my CSS missed…)
    2) customized the code to support a different button text on an archive page of a custom post type
    I’m new to php so if you notice anything wrong with this please shout!

    
    // Add a "Read more..." button for manual excerpts to match that for automatic excerpts
    // And provide different text for the read more button where post type is 'md'
    
    add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' );
    function tu_excerpt_metabox_more( $excerpt ) {
    	$output = $excerpt;
    	
    	if ( has_excerpt() && ( 'md' == get_post_type())){
    			$output = sprintf( '%1$s <p class="read-more-container"><a class="read-more button" href="%2$s">View recording ...</a></p>',
    			$excerpt,
    			get_permalink()
    		);
    	}
    	
    	elseif ( has_excerpt() ) {
    		$output = sprintf( '%1$s <p class="read-more-container"><a class="read-more button" href="%2$s">Read more ...</a></p>',
    			$excerpt,
    			get_permalink()
    		);
    	}
    	
    	return $output;
    }
    
    #1344808
    Leo
    Staff
    Customer Support

    Can you open a new topic for your question as this one is a bit old with multiple authors already?

    Thanks ๐Ÿ™‚

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