Place in your 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); }
Make sure to change “your_field_name”.
Use in your template:
echo custom_field_excerpt();
Thanks for this code.
Really nice code!! i got a question though, its possible insert the permalink into the […]?
thanks again!!
Carlos.-
Sure, you would just need to get the permalink and then wrap it in the link. Add a new line to the function:
That gives you the permalink. Then change the line that starts with $excerpt_more to:
$text = get_field(‘question_1’); //Replace ‘your_field_name’