Custom excerpt length ignored after update

Home Forums Calendar Products Events Calendar PRO Custom excerpt length ignored after update

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1132382
    Gabrielle
    Participant

    Hi there!

    About a week ago I updated my functions.php file to create a custom length of my calendar excepts in list view. It contained an if/else statement that allowed for my blog post excerpts to be a different length than the calendar excerpts. This worked fine until I updated all the calendar plugins (4.2.1)

    Right now this is my code that used to work:

    
    if ( ! function_exists( 'custom_excerpt_length' ) ) {	
    	function custom_excerpt_length( $length ) {
    		
    		global $data;
    		
    		if ( !empty ( $data['blog_excerpt_limit'] ) ) { 
    			$excerpt = $data['blog_excerpt_limit']; 
    		}
    		elseif (is_category()) {
    			$excerpt = 55;
    		}
    		else {
    			$excerpt = 20;
    		}
    		return $excerpt;
    	}
    }
    
    if ( ! function_exists( 'clear_excerpt_more' ) ) {	
    	function clear_excerpt_more( $more ) {
    		return '...';
    	}
    }
    
    	add_filter('excerpt_more', 'clear_excerpt_more');
    	add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
    
    if ( ! function_exists( 'zn_limit_content' ) ) {	
    	function zn_limit_content($string, $word_limit)
    	{
    		$words = explode(" ",$string);
    		return implode(" ",array_splice($words,0,$word_limit));
    	}
    }
    

    If I just use the code below suggested in other forums posts, it doesn’t effect any of my excerpts. However, it did before the update:

    
    function custom_excerpt_length( $length ) {
        return 20;
    }
    add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
    

    Any thoughts on what might have changed?

    Thanks so much!

    • This topic was modified 7 years, 10 months ago by Gabrielle. Reason: spelling
    #1132594
    Josh
    Participant

    Hey Shawn,

    Thanks for reaching out to us!

    In your initial excerpt length function, try using if( !tribe_is_event_query() ) instead of if( is_category() ) and see if that works for you here. That will allow for any non-event based excerpt to display at 55 and the events to display at 20.

    Let me know if this helps.

    Thanks!

    #1133907
    Gabrielle
    Participant

    Hi there!

    Turns out there was someone else populating the events on my team who was manually adding excerpts. Once I got them to remove those, my code worked just fine once again đŸ™‚ That code you provided looks much cleaner than what I have though, and I’m gonna give it a whirl. Thanks again!

    #1134698
    Josh
    Participant

    Hey Shawn,

    No problem, I’m glad you were able to find the issue here.

    I’ll go ahead and close this thread for now. If you have any further questions, please don’t hesitate to open a new one.

    Thanks!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Custom excerpt length ignored after update’ is closed to new replies.