Advertisement
Guest User

Untitled

a guest
Jan 24th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. function advanced_custom_field_excerpt() {
  2. global $post;
  3.  
  4. // check if the flexible content field has rows of data
  5. if( have_rows('post_flexible_content') ):
  6.  
  7. // loop through the rows of data
  8. while ( have_rows('post_flexible_content') ) : the_row();
  9.  
  10. $text = get_sub_field('flexible_text_editor');
  11. if ( '' != $text ) {
  12. $text = strip_shortcodes( $text );
  13. $text = apply_filters('the_content', $text);
  14. $text = str_replace(']]>', ']]>', $text);
  15. $excerpt_length =30; // 30 words
  16. $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
  17. $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
  18. break;
  19. }
  20.  
  21. endwhile;
  22.  
  23. else :
  24.  
  25. // no layouts found
  26.  
  27. endif;
  28.  
  29. return apply_filters('the_excerpt', $text);
  30. }
  31. add_shortcode("flexible-excerpt", "advanced_custom_field_excerpt");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement