WordPress – customising the_excerpt() not working

I have added the following code to my functions.php script within my theme:

function custom_excerpt_length( $length ) {
    return 15;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

function new_excerpt_more( $more ) {
    return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');

as suggested on this page: http://codex.wordpress.org/Template_Tags/the_excerpt

Read More

but the length of the excerpt is still the default 55 words and the string at the end is still [...] rather than ....

WordPress version is 3.4.1

The code I am using to display the excerpt is simply:

the_excerpt();

Does anyone have any ideas on how to fix it so that the additions to my functions.php work?

Related posts

Leave a Reply

2 comments

  1. Use this code for limit the content

    <?php query_posts('cat=ID'.'&showposts=NO. OF POST') ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    <?php the_post_thumbnail(); ?>
    <p><?php echo substr(get_the_excerpt(), 0,65).' [...]'; ?></p>
    <a href="<?php the_permalink(); ?>">Read More...</a>
    
    
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
    <?php endif;?>
    
  2. I’ve managed to achieve the desired result by using something along the lines of:

    $excerpt = get_the_excerpt();
    $excerpt = preg_replace('/s+?(S+)?$/', '', substr($excerpt, 0, 71));
    echo '<div class="blog-posts-grid-box-excerpt">' . $excerpt . '...</div>';
    

    Hopefully this is some use to someone who discovers this question.