Skip to content

Instantly share code, notes, and snippets.

@Sanabria
Created August 1, 2018 00:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Sanabria/6a8ceb1596b3fd0b1f805ed2c47814d0 to your computer and use it in GitHub Desktop.
Get Excerpt from an Advanced Custom Field ACF
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); !!}
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();
@Sanabria
Copy link
Author

Sanabria commented Aug 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment