Is there an easy way to add another ‘read more’ link? I’m using the standard ‘continue reading’ link for some posts but I also want to use a different text like ‘more info’ for other posts. Can I do this using the_excerpt
?
Later update:
This are the two standard twentyelven functions that are used for the ‘read more’ or ‘continue reading’ links.
function twentyeleven_continue_reading_link() {
return ' <a href="'. esc_url( get_permalink() ) . '">' . __( '<span class="more">more +</span>', 'twentyeleven' ) . '</a>';
}
function twentyeleven_auto_excerpt_more( $more ) {
return ' …' . twentyeleven_continue_reading_link();
}
add_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' );
Based on amit code I though about including an if / else
statement in the twentyeleven_auto_excerpt_more
function, but I did something wrong because it doesn’t work.
This is the code:
function twentyeleven_auto_excerpt_more( $more ) {
$read_more_link_2 = "View Image";
if ( in_category( 'events' )) {
return $read_more_link_2;
} else {
return ' …' . twentyeleven_continue_reading_link();
}
add_filter( 'excerpt_more', 'twentyeleven_auto_excerpt_more' );
I think it’s obvious that PHP is not my strong point.
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 thecontinue reading
withView Image
if post is inimage
category.Update #1
Put this code at the end of your theme’s
functions.php
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 whenthe_excerpt()
is used in themewpse_60184_the_content_more
will replace the default read more link with new one. Will work with<!-- more -->
tag.You can use the excerpt_more filter hook.
I suggest just adding a specific meta data field to posts that this filter would then use to overwrite the default text.
Possible PHP could be as follows (untested):