Forums

Changin gthe excerpt length based on page (2 posts)

  1. nadine00
    Member
    Posted 2 years ago #

    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!

  2. stvwlf
    Member
    Posted 2 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic