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.

In the get_blog_excerpt() function below, the excerpt_more filter works perfectly when the post excerpt is not present, however, when the post has an excerpt, I'm not getting the "Read More" link.

I understand that the_excerpt first checks to see if a post excerpt is present, which is fine, but I want the read more link applied to it too.

What do I need to change in order to make the excerpt_more apply in all cases?

function get_blog_excerpt(){
    add_filter('excerpt_length', 'ce4_excerpt_length');
    add_filter('excerpt_more', 'ce4_excerpt_more');
    return the_excerpt();
}

function ce4_excerpt_length($length) {
    return 150;
}

function ce4_excerpt_more($more) {
    global $post;
    return '...<a href="'. get_permalink($post->ID) . '">Read More</a>';
}


function get_blog_links(){
    global $post;
    setup_postdata($post);
    $myposts = get_posts($args);echo '<div id="menuFooterRecent" class="blog">'; 
    echo '<ul>'; 
    foreach($myposts as $idx=>$post){ ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php 
    echo get_blog_excerpt();
    echo '<div style="clear:both">&nbsp;</div>';?></li>
    <?php } echo '</ul></div>';
}

The code above is inside functions.php

The code below is inside archive.php

<?php 
if(is_category()){
    if (get_query_var('cat') == get_category_by_slug('blog')->term_id){
        get_blog_links();
    }
    else 
    {
    get_category_links();
    }
} ?>    
share|improve this question
    
Where is get_blog_excerpt() called (or hooked)? –  Chip Bennett Jun 17 '11 at 19:33
    
From inside a function in functions.php –  Scott B Jun 17 '11 at 20:23
    
Could be caused by a plugin. I just had the exact same problem, my code in functions.php to change the excerpt's length and look is fine (tested in a clean wp installation) but it's been "killed" by a plugin, 'Event Calendar 3.1.4' in my case. It all works fine if i switch the plugin off. Try to give a look in this way. –  kevin Jul 21 '11 at 15:53
    
Solved my problem using this plugin: wordpress.org/extend/plugins/advanced-excerpt –  kevin Jul 21 '11 at 16:00

1 Answer 1

up vote 1 down vote accepted

I'm going to assume that you're calling get_blog_excerpt() in your template somewhere?

If so, what happens if you simply call the_excerpt(), and then pull the two add_filter() calls out of the container function? i.e. functions.php would just look like:

function ce4_excerpt_length($length) {
    return 150;
}
add_filter('excerpt_length', 'ce4_excerpt_length');

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

And in your template, you would just call the_excerpt().

If that works, then I suspect the issue is that your filters aren't getting applied - probably due to being wrapped in the container function.

share|improve this answer
    
Chip, thanks for the tip. But moving the filters outside the container does not appear to have an effect on the script. It operated the same regardless. –  Scott B Jun 17 '11 at 20:29
    
get_blog_excerpt is called from a function inside of functions.php, which is in turn called from a function outside the loop in archive.php –  Scott B Jun 17 '11 at 20:30
    
So, you tried just calling the_excerpt()? –  Chip Bennett Jun 17 '11 at 21:20

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.