Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Currently, I call the_excerpt via traditional means:

<?php the_excerpt(); ?>

But I add a filter in functions.php for a custom "read more" message.

// Changing excerpt more
function new_excerpt_more($post) {
    return ' <a class="read_more" href="'. get_permalink($post->ID) . '">' . 'read more' . '</a>';
}
add_filter('excerpt_more', 'new_excerpt_more'); 

Here's the problem; I would like to call the_excerpt inside posts as well without any read more type of link being displayed while leaving the_exerpt being used in the actual excerpts unimpacted.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Just add the filter where you need it.

Define the filter callback in functions.php but don't add the filter...

// Changing excerpt more
function new_excerpt_more($post) {
    return ' <a class="read_more" href="'. get_permalink($post->ID) . '">' . 'read more' . '</a>';
}

In your template file just before you need the custom more link:

add_filter('excerpt_more', 'new_excerpt_more'); 

And remove it afterwards

remove_filter('excerpt_more', 'new_excerpt_more'); 

Or make it self-removing...

function new_excerpt_more($post) {
    remove_filter('excerpt_more', 'new_excerpt_more'); 
    return ' <a class="read_more" href="'. get_permalink($post->ID) . '">' . 'read more' . '</a>';
}
share|improve this answer
    
Thanks, this worked! Maybe this is a stupid question, but when I use this code in my single posts it is displaying [...] after the excerpt; how would I remove that or properly call in the single posts. I am using your suggested code in my archives for displaying actual excerpts and using the_excerpt in single posts to display the post's excerpt on the post's page. –  AndrettiMilas Jun 24 '13 at 19:51
    
That is really your code. I just re-organized it. Are you sure that this code is involved when you get the [...]? –  s_ha_dum Jun 24 '13 at 20:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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