0

I'm trying to add a button to every post excerpt. But I get the button without href:

function new_excerpt_more( $more ) {                    
    global $post;
    return "<p><a href='" .get_permalink( $post->ID ) ."' class='btn' >Read more</a></p>";
}
add_filter('excerpt_more', 'new_excerpt_more');

The problem only occurs when I'm showing the excerpts with a shortcode command within the content:

function show_last_articles() {
    $args = array( 'posts_per_page' => 3, 'category_name' => 'xyz');
    $lastposts = get_posts( $args );
    foreach ( $lastposts as $post ):
        setup_postdata( $post );
            $return = "<div class='excerpts'>";
            $return .= "<h2><a href='" .get_the_permalink( $post->ID ) ."'>" .get_the_title( $post->ID ) ."</a></h2>";
            $return .= "<div>" .get_the_excerpt( $post->ID ) ."</div>";
            $return .= "</div>";
    endforeach; 
    wp_reset_postdata();
    return $return;
}
add_shortcode( 'last_articles', 'show_last_articles');

Whats wrong?

1 Answer 1

0

This only makes the read more link a button.

add_filter( 'excerpt_more', 'wpsites_read_more_link' );
    function wpsites_read_more_link( $more ) {
        return '... <a class="more-link button" href="' . get_permalink() . '">Continue Reading</a>';
}

Replace the button class with your themes button class.

2
  • which influence has the button class on the output of get_permalink() function? Commented May 30, 2015 at 14:19
  • Don't follow. This doesn't help with your short code, it only makes the read more link a button. Commented May 30, 2015 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.