• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2785

Original Genesis & WooCommerce Tutorials & 6000+ Guaranteed Code

Snippets

  • Try Premium
  • Log in

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.

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags