free tuts

Sometimes we need to set different number of words for post excerpt on various types of pages. It can be done very easy with conditional tag. For example, we want to set X words for blog index while on other pages (“categories” for example) we want to set Y words. In the snippet below (this piece of code we write in functions.php) we want 25 symbols for post excerpt for the front page and 15 symbols for all other pages:

We may widen the if statement with elseif and else.

In the piece of the code above we set 15 words for blog index, 33 words for custom post type (taxonomy) “the_extras”, 30 words for custom post type (taxonomy) “the_specials” and 17 words for any other page. This way we may manipulate the number of words of post excerpt on various page types and get the desired result.