[Resolved] How to display 'read more' when using the excerpt field

Home Forums Support [Resolved] How to display 'read more' when using the excerpt field

Home Forums Support How to display 'read more' when using the excerpt field

Viewing 15 posts - 16 through 30 (of 32 total)
  • Author
    Posts
  • #405848
    Mark

    Having spent quite some time troubleshooting this (before finally searching here – duh!!!), it’s good that there is an explanation.

    However, given that this has come up before from a number of folks and has caused some confusion, is it reasonable to expect that the theme might handle this in a more robust/predictable way in a future release, to avoid others going down this same path?

    Thank you.

    #406032
    Tom
    Lead Developer
    Lead Developer

    Glad it helped!

    I wish WP itself had a better way of handling this. I’ll look into it some more and will come up with something solid enough for the theme 🙂

    #485888
    Jakob

    HI Tom,

    I’ve absolutly no clue, where to put:

    add_filter( ‘wp_trim_excerpt’, ‘tu_excerpt_metabox_more’ );
    function tu_excerpt_metabox_more( $excerpt ) {
    $output = $excerpt;

    if ( has_excerpt() ) {
    $output = sprintf( ‘%1$s Read more‘,
    $excerpt,
    get_permalink()
    );
    }

    return $output;
    }

    in order to get a “read more” – Button while using excerpt field in Blog view.

    #485995
    Leo
    Staff
    Customer Support
    #579888
    Pascal

    Hi
    And for those ones who are looking for (like me), to have a button with the link text what has been set as the ‘Read more label’ in the Customiser :

    add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' );
    function tu_excerpt_metabox_more( $excerpt ) {
    	$output = $excerpt;
        $settings = wp_parse_args( 
    		get_option( 'generate_blog_settings', array() ), 
    		generate_blog_get_defaults() 
    	);
      
      
    	if ( has_excerpt() ) {
    		$output = sprintf( '%1$s <p class="read-more-button-container"><a class="button" href="%2$s">%3$s</a></p>',
    			$excerpt,
    			get_permalink(),
    			wp_kses_post( $settings['read_more'] )
    		);
    	}	
    	return $output;
    }
    #580162
    Leo
    Staff
    Customer Support

    Awesome thanks for sharing!

    #589176
    Robert

    I’d like to use the code above in https://generatepress.com/forums/topic/how-to-display-read-more-when-using-the-excerpt-field/#post-370520. By default it ends up at the right after my handcrafted excerpt. How do I style it so that it’s in a separate block so I can center it under the excerpt, apply padding, etc.

    #589258
    Leo
    Staff
    Customer Support

    Is this for adding read more when using custom excerpt field?

    If so I think the button one is what you are looking for more:
    https://docs.generatepress.com/article/activating-read-custom-excerpt/

    #589419
    Robert

    Hi Leo,

    Yes, I’m using a custom excerpt. I’m trying to mimic the way the Site Library’s Classic theme centers “Read More” under the excerpt. In looking over the reference you posted, I see I need to add the p class called read-more-container to my Read More link snippet.

    Thanks!

    #589652
    Leo
    Staff
    Customer Support

    No problem!

    #594214
    Christian Zumbrunnen

    It’s just fantastic I could find help so easily here!
    Thanks Tom.
    GeneratePress and your support is just incredible fantastic!

    When “Display read more as button” is checked the “read more” link is enclosed by a

    <p class="read-more-container"</p>

    How could I accomplish that this is rendered the same way here?

    #594216
    Christian Zumbrunnen

    Sorry, it was up there and I overlooked it.

    #594397
    Leo
    Staff
    Customer Support

    Glad you figured out!

    #715161
    Kemo

    seems like the classes for the button changed a bit? updated code that works for me(add to child’s functions.php):

    //fix read more button with manual excerpts field
    add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' );
    function tu_excerpt_metabox_more( $excerpt ) {
    	$output = $excerpt;
            $settings = wp_parse_args( 
    		get_option( 'generate_blog_settings', array() ), 
    		generate_blog_get_defaults() 
    	);
    	if ( has_excerpt() ) {
    		$output = sprintf( '%1$s <p class="read-more-container"><a class="read-more button" href="%2$s">%3$s</a></p>',
    			$excerpt,
    			get_permalink(),
                            wp_kses_post( $settings['read_more'] )
    		);
    	}
    	return $output;
    }
    #715703
    Leo
    Staff
    Customer Support
Viewing 15 posts - 16 through 30 (of 32 total)
  • The topic ‘How to display 'read more' when using the excerpt field’ is closed to new replies.