• Thanks to the developers for Atahualpa, the most versatile and incredibly useful WordPress template I’ve ever used — and likely the only one I’ll ever use again!

    I think I’ve stumbled upon a missing line in the Custom Excerpts function in functions.php (bfa_wp_trim_excerpt). I am hoping this can help anyone else who bumps into it, or be fixed in a future release.

    1) The function starts with a conditional that checks to see if the post has a manually created excerpt (in the Excerpts field on your post editor). If it doesn’t, it process the first X words of the post according to the settings you chose in the Atahualpa Theme Options.

    2) If the post does have a manually created excerpt, the function explodes the value of the_excerpt into an array, then counts the number of words.

    3) If the word count is greater than what you allowed in the Options, it truncates it accordingly.

    What is missing from the second half of the function (manually created excerpts) is:

    $excerpt_length = $bfa_ata['excerpt_length'];

    This is defined and used inside the first conditional statement. But when $excerpt_length is called again in the second conditional (for the word count check), it hasn’t been defined. The result for me is that WP was truncating my excerpt at some arbitrary number (26 words) and ending it […]

    The repaired function looks like this:

    // Custom Excerpts
    function bfa_wp_trim_excerpt($text) { // Fakes an excerpt if needed
    
    	global $bfa_ata;
    
    	if ( '' == $text ) {
    		$text = get_the_content('');
    		$text = apply_filters('the_content', $text);
    		$text = str_replace(']]>', ']]>', $text);
    		$text = strip_tags($text, $bfa_ata['dont_strip_excerpts']);
    		$excerpt_length = $bfa_ata['excerpt_length'];
    		$words = explode(' ', $text, $excerpt_length + 1);
    	} else {
    		$words = explode(' ', $text);
    		$excerpt_length = $bfa_ata['excerpt_length'];
    	}
    
    	if (count($words) > $excerpt_length) {
    		array_pop($words);
    		$custom_read_more = str_replace('%permalink%', get_permalink(), $bfa_ata['custom_read_more']);
    		$custom_read_more = str_replace('%title%', the_title('','',FALSE), $custom_read_more);
    		array_push($words, $custom_read_more);
    		$text = implode(' ', $words);
    	}
    
    	return $text;
    }
    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'bfa_wp_trim_excerpt');

    Thanks again for a great template!

  • The topic ‘Atahualpha: Error in Custom Excerpts Function’ is closed to new replies.