Created
December 1, 2014 14:42
-
-
Save laurenclark/7d57164528850f2bd836 to your computer and use it in GitHub Desktop.
Custom Field Wysiwyg Excerpt
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
//Get the excerpt for main_content | |
function custom_field_excerpt() { | |
global $post; //Contains data from current post in the loop. | |
$text = get_field('main_content'); //Cache the custom field to variable. | |
if ( '' != $text ) { //Check if it's empty. | |
$text = strip_shortcodes( $text ); //Remove any shortcodes as this is just an excerpt | |
$text = apply_filters('the_content', $text); //Apply the_content to $text | |
$text = str_replace(']]>', ']]>', $text); | |
$excerpt_length = 20; // 20 words | |
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]'); //Apply the excerpt | |
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); // Trim words and add on the excerpt | |
} | |
return apply_filters('the_excerpt', $text); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WordPress custom field excerpt.