You may be able to do something like this (but I haven’t tested it to see if it will actually work):
function custom_excerpt_length( $length ) {
if ( is_page( /*Page ID goes here*/ ) ) {
return 20;
}
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
Hi JPry,
Would the page ID I’m testing for be the page the post appears on or the page I want to change the excerpt length on?
Cheers,
Rab
Hi guys – I’m trying to do the same thing… isn’t there a way to do this and avoid messing with functions.php alltogether?
ie – can’t you just say “display first XX words of the excerpt here” and be done with it?
I’m working on a new site where part of one (long) page is being displayed on the homepage and I’d like to use the excerpt to cut it off after so many words before having it display a “continue reading…” link.
page as in ‘static page’ ?
excerpts don’t really work with pages.
you could try <!--nextpage-->
instead.
http://codex.wordpress.org/Styling_Page-Links
or add the filter function and call into the template before the loop(instead of into functions.php)
i have not widely tried it, but it seems possible.
<?php function excerpt_length_for_template($length) {
return 5;
}
add_filter('excerpt_length', 'excerpt_length_for_template');
?>
If excerpts don’t work well with static pages, could I load it in with the_content(), trim the number of words and add a continue link to the end?
not sure, because the continue link would point to the same page which would only show the short form – kind of catch-22
(i tried to overcome this by checking the referring link url:
http://codex.wordpress.org/Function_Reference/wp_get_referer
and just using the last part after the / )
a possible hack is here:
in page.php (or your page template) replace <?php the_content(); ?>
with:
http://pastebin.com/y0C0569V
(not widely tested at all;
does not work together with <!--nextpage-->
edit:
fix for that: http://pastebin.com/WSyXCJAy )