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?

  • Are you adding excerpt in excerpt meta field? – Vinod Dalvi Sep 5 '13 at 17:10
  • No. Does that make a difference? – Sebastian Starke Sep 5 '13 at 17:16
  • Yes it makes difference. See answer for more info. – Vinod Dalvi Sep 5 '13 at 17:19
  • Where are you adding the above two filters ( in which file )? – Vinod Dalvi Sep 5 '13 at 17:25
  • In functions.php. – Sebastian Starke Sep 5 '13 at 18:00
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' );
?>
  • I'm using WP 3.6. I forgot to mention that. – Sebastian Starke Sep 5 '13 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 – Vinod Dalvi Sep 6 '13 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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