Site logo

Archived topic

Read More styling with custom excerpt

2 replies · Started by Matt on June 1, 2022

Viewing posts 1–3 of 3

Hi, I use the custom excerpt for blog pages and homepage. I used the PHP snippet given in the forum to add the read more text back, however the .read-more class doesn't style it. I can't find a CSS class to use to style the text using dev tools either.

Additionally, in the customizer it doesn't matter what text is given, the home page and archives always show "Read more". I'm assuming the PHP just prints what is put in the last line below. Can that be changed to be done from the customizer? If not no problem but how can I add a CSS class to style it?

        $output = sprintf( '%1$s <a href="%2$s">%3$s</a>',
            $excerpt,
            get_permalink(),
            __( 'Read more text goes here', 'generatepress' )

Nevermind, I just did this for anyone searching the future


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

    if ( has_excerpt() ) {
        $output = sprintf( '%1$s <a href="%2$s" class="read-more">%3$s</a>',
            $excerpt,
            get_permalink(),
            __( 'Read more →', 'generatepress' )
        );
    }

    return $output;
}

Glad to hear that you've found a solution :)

This archived topic is closed to new replies.