Different Excerpt Lengths For Posts & Archives

The PHP code in this free quick tip enables you to conditionally change the length of the excerpt.

Based on this question from a member of the Genesis community :

Looking to change the excerpt length. I’d like to have it as an if page id is this return x, else be x so the homepage can be different.

Here’s the code for your child themes functions.php file :

In the above example, the excerpt length will be set at 10 words if the post is in the travel category otherwise the excerpt length for all other posts is set at 100 words.

This code includes a ternary operator and conditional tag.

You will need to swap out the conditional tag with your own to suit your own requirements.

Assumes you have set excerpts in Genesis > Theme Settings > Content Archives.

Was This Tutorial Helpful?

Free

$0

Access only to all free tutorials per month.



Monthly

$75

Access to 10 premium tutorials per month.


Tutorial Request


Includes code guarantee and coding support.

Yearly

$500

Access to 15 premium tutorials per month.


Monthly Tutorial Request


Includes code guarantee and priority coding support.