• Hi,

    I’ve been trying to change the excerpt on some articles based on a page, so for example the home page has 60 words, a sub section has 20 words. I know i’m doing something wrong here, but i’m not sure what. I’m not a programmer, and it shows. lol. But yeah, any suggestions would be welcome. ??

    <?php function new_excerpt_length($length) {
    
    	if (is_page ('whoscoming')) {
    	$length = 20;
    	}else {
    	$length = 60;
    	}
    }
    add_filter('excerpt_length', 'new_excerpt_length');
    
    ?>

    Thanks!

Viewing 1 replies (of 1 total)
  • you are missing one line

    <?php function new_excerpt_length($length) {
    
    	if (is_page ('whoscoming')) {
    	$length = 20;
    	}else {
    	$length = 60;
    	}
    ADD-->  return $length;
    }
    add_filter('excerpt_length', 'new_excerpt_length'); ?>

    return tells the function to send the calculated length back to the line of code that executed the function

Viewing 1 replies (of 1 total)
  • The topic ‘Changin gthe excerpt length based on page’ is closed to new replies.