[Resolved] Adding “read more” to excerpts only on blog page

Home Forums Support [Resolved] Adding “read more” to excerpts only on blog page

Home Forums Support Adding “read more” to excerpts only on blog page

  • This topic has 3 replies, 2 voices, and was last updated 4 years ago by Leo.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1435321
    Ben

    Hi, I’m using this code to modify excerpts:

    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="read-more button" href="%2$s">%3$s</a></p>',
                $excerpt,
                get_permalink(),
                __( 'Read more', 'generatepress' )
            );
        }
    	
        return $output;
    }

    Is there a way to target this just on the blog page, eg
    if ( has_excerpt() && is_front_page() )

    ?

    #1435528
    Leo
    Staff
    Customer Support

    Hi there,

    The conditional tag depends on if you your blog page is the front page or not.

    See the explanation here:
    https://codex.wordpress.org/Conditional_Tags#The_Blog_Page

    Let me know if this helps ๐Ÿ™‚

    #1435579
    Ben

    Thanks Leo, you’re right, it was is_home() I should have used.
    Many thanks
    Ben

    #1435632
    Leo
    Staff
    Customer Support

    No problem ๐Ÿ™‚

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