0

I tried to change the excerpt length and the more tag the way it is described in the codex:

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


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

this is how I call the excerpt from within the template:

<?php the_excerpt(); ?>

But it still has the same length and more tag as before. How can that be?

8
  • Are you adding excerpt in excerpt meta field? Commented Sep 5, 2013 at 17:10
  • No. Does that make a difference? Commented Sep 5, 2013 at 17:16
  • Yes it makes difference. See answer for more info. Commented Sep 5, 2013 at 17:19
  • Where are you adding the above two filters ( in which file )? Commented Sep 5, 2013 at 17:25
  • In functions.php. Commented Sep 5, 2013 at 18:00

1 Answer 1

0

excerpt_length filter does not work on manually added filter so you use wp_trim_excerpt function, you can develop code same as following to achieve it.

<?php
if( has_excerpt() ){
    the_excerpt();
} else {
    wp_trim_excerpt();
}
?>

excerpt_more does not work on WordPress version 2.8.x and Older for those versions you have to use following filter.

<?php
function new_excerpt_more( $excerpt ) {
return str_replace( '[...]', '...', $excerpt );
}
add_filter( 'wp_trim_excerpt', 'new_excerpt_more' );
?>
2
  • I'm using WP 3.6. I forgot to mention that. Commented Sep 5, 2013 at 18:01
  • @Lord_Mord Are you checking it on search or archive page? Because i checked your code in pastebin and you have added is_search() || || !is_single() condition Commented Sep 6, 2013 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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