• Resolved Adwiz

    (@adwiz)


    Currently when showing excerpts, the title links to the content, but even when I use the following :

    <?php the_excerpt('Read the rest of this entry &raquo;'); ?>

    There is no “Read the rest of this entry” at the end of the excerpt. I want both the title AND a link at the end of the excerpt to go to the full post, because many people don’t know they can click the title.

    How do I add an automatic link at the end of the excerpt that will go to the permalink? The closest I’ve come is something like this but it’s not correct PHP and my PHP knowledge is at the very beginner level:

    <?php if ( is_category() || is_archive() ) {
    	the_excerpt() "<a href="<?php the_permalink() ?>"Read more &raquo;</a>";
    } else {
    	the_content();
    } ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Try:

    <?php if ( is_category() || is_archive() ) {
    	the_excerpt();?>
    	<a class="more-link" href="<?php the_permalink();?>">Read more &raquo;</a>
    <?php } else {
    	the_content();
    } ?>
    Thread Starter Adwiz

    (@adwiz)

    That’s great! Thanks, esmi.

    The only question I have is how would I write the code if I didn’t want it to create a the “Read more” link on a new line under the excerpt, but actually place it at the end of the excerpt text itself, as if it were part of the excerpt text?

    Totally untested but you could try adding the following to the theme’s functions.php:

    // Set up a proper read more link for post extracts
    function proper_readmore($more) {
    	if ( is_category() || is_archive() ) {
    		$link = ' <a class="more-link" href="' . get_the_permalink() . '">Read more &raquo;</a>';
    	}
    	else $link = '';
    	return $link;
    }
    add_filter('excerpt_more', 'proper_readmore');

    If that works, simply using <?php the_excerpt();?> should generate the link on category or archive pages.

    Thread Starter Adwiz

    (@adwiz)

    Thanks! I’ll try it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Creating a “read more” link in excerpts’ is closed to new replies.