Support

Account

Home Forums General Issues Can't get Excerpts to work Reply To: Can't get Excerpts to work

  • Hi @cstrasz

    If you add this to the functions file:

    
    // Custom Excerpt function for Advanced Custom Fields
    function custom_field_excerpt() {
    	global $post;
    	$text = get_field('your_field_name'); //Replace 'your_field_name'
    	if ( '' != $text ) {
    		$text = strip_shortcodes( $text );
    		$text = apply_filters('the_content', $text);
    		$text = str_replace(']]>', ']]>', $text);
    		$excerpt_length = 20; // 20 words
    		$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
    		$text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
    	}
    	return apply_filters('the_excerpt', $text);
    }
    

    Ensure you replace ‘your_field_name’ with the actual ACF field you need to use.

    In your template (possibly archive.php), where you need to find the loop and add:
    echo custom_field_excerpt();

    Depending on your theme/custom code, you may need to adjust where the code is displayed.

    For example, you may have the loop which has an include to another file to show the content, so the above line may need adding there instead.