Created
August 1, 2018 00:22
-
-
Save Sanabria/6a8ceb1596b3fd0b1f805ed2c47814d0 to your computer and use it in GitHub Desktop.
Get Excerpt from an Advanced Custom Field ACF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function custom_field_excerpt($text, $words) { | |
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 = $words; // 20 words | |
$excerpt_more = apply_filters('excerpt_more', ' foobar' . '[...]'); | |
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); | |
} | |
return apply_filters('the_excerpt', $text); | |
} | |
{!! App\custom_field_excerpt($historia['texto_historia'], 30); !!} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
echo custom_field_excerpt(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Taken from: http://wpmunchies.com/get-excerpt-advanced-custom-field-acf/