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

WP SITES

2662

Original Genesis Tutorials & 5000+ Guaranteed Code

Snippets

  • Support
  • Newsletter
  • Videos
  • Log in

Premium Member? - Request custom code

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

PHP Code

template_include

get_body_class

if else

array

class_exists

foreach

sprintf

add_action

printf

variable

Advertise · WPEngine · Genesis · Log in

  • How Premium Membership Works
  • Sign Up
  • Support
  • Subscription Details/Invoice
  • Tagged Tutorials
  • Access-Download Problems