Different ‘read more’ links

How about using condition to change the readmore links.

Here is an sample code which returns a different read more text based upon the category of post. You should read the official codex page to know more about other conditional tags you can use in wordpress.

Usage – put this code into your theme’s functions.php file. This code will replace the continue reading with View Image if post is in image category.

<?php
        function wpse_60184_new_readmore_link( $more ) {
                $read_more_link_2 = "View Image";
                if ( in_category( 'image' )) {
                        return $read_more_link_2;
                }
        }
        add_filter('excerpt_more', 'wpse_60184_new_readmore_link');
?>

Update #1

Put this code at the end of your theme’s functions.php

//this will create read morelink when the_excerpt() is used
function wpse_60184_the_excerpt_more($more) {
    in_category( 'events' ) ? $my_read_more_text="Read event" : $my_read_more_text="Read more"; 
    global $post;
    return '<a href="'. get_permalink($post->ID) . '">'.$my_read_more_text.'</a>';
}
add_filter('excerpt_more', 'wpse_60184_the_excerpt_more');

//this will change the read more link when <!-- more --> is used & the_content()       
function wpse_60184_the_content_more( $more_link, $more_link_text ) {
    in_category( 'events' ) ? $my_read_more_text="Read events" : $my_read_more_text="Read more";    
    return str_replace( $more_link_text, $my_read_more_text, $more_link );
}
add_filter( 'the_content_more_link', 'wpse_60184_the_content_more', 10, 2 );

The second code is tested with twenty eleven theme and it appears to be working fine on localhost.

  • wpse_60184_the_excerpt_more creates a read-more link when the_excerpt() is used in theme
  • wpse_60184_the_content_more will replace the default read more link with new one. Will work with <!-- more --> tag.