• Resolved jpanizzoli

    (@jpanizzoli)


    I’d like to have a custom excerpt length on the home page, and a different excerpt length on the category pages. I’m trying to override the Theme Options >> Excerpt Length to accomplish this.

    Using functions.php does not seem to work. I’ve tried various versions of this code:

    function custom_excerpt_length( $length ) {
    	if( is_category() ) {
    	return 54;
    	} else {
    	return 34;
    }
    }
    add_filter('excerpt_length', 'custom_excerpt_length');

    I’ve tried to set a custom excerpt length for is_category and for is_front_page, but neither seems to override the excerpt length set in the theme (Theme Options >> Excerpt Length). Any suggestions? Thanks for your help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi jpanizzoli. Welcome to the Hueman forum. The theme has a built-in function to add an excerpt_length filter. The easiest thing to do is override the theme function by copying it to your child theme functions.php file and modifying it:

    function alx_excerpt_length( $length ) {
        if ( is_category() ) {
            return 54;
        } else {
            return ot_get_option('excerpt-length',$length);
        }
    }

    If you don’t want to use the theme option excerpt length then just replace that line with a different value.

    Thread Starter jpanizzoli

    (@jpanizzoli)

    THANK YOU! That worked great ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom excerpt length on home page…’ is closed to new replies.