Last active
April 13, 2020 05:37
-
-
Save marcwiest/7114910 to your computer and use it in GitHub Desktop.
Better WordPress Post–Page / Content–Excerpt Function
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
| <?php | |
| function better_wp_post_content( $word_limit=false, $force_excerpt=false, $do_shortcode=false ) { | |
| $post = get_post(); | |
| $excerpt_metabox = $post->post_excerpt; | |
| // If word limit was used, return the excerpt. | |
| if ( is_int( $word_limit ) ) : | |
| $excerpt = $force_excerpt ? $excerpt_metabox : get_the_excerpt(); | |
| $excerpt = explode( ' ', $excerpt ); | |
| $excerpt = implode( ' ', array_slice( $excerpt, 0, $word_limit ) ); | |
| $return = $excerpt; | |
| endif; | |
| // If word limit is FALSE, return the content. | |
| if ( $word_limit == false ) | |
| $return = $force_excerpt ? $excerpt_metabox : get_the_content(); | |
| // Activate $do_shortcode if it's get_the_content(). | |
| if ( $word_limit == false && $force_excerpt == false ) | |
| $do_shortcode = true; | |
| // Check $do_shortcode. | |
| if ( $do_shortcode ) | |
| $return = do_shortcode( $return ); | |
| return wpautop( $return ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment