Created
July 22, 2016 17:47
-
-
Save rbk/661a4b640107166d653dee60a4583e30 to your computer and use it in GitHub Desktop.
Get an excerpt if one doesn't exist
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 generate_awesome_excerpt( $id, $character_limit, $ending ) { | |
| if( gettype($character_limit) != 'integer' ) { | |
| $character_limit = 100; | |
| } | |
| $post = get_post($id); | |
| $content = $post->post_content; | |
| $content = strip_shortcodes( $content ); | |
| $content = strip_tags($content); | |
| $content = substr($content, 0, $character_limit); | |
| $content = $content . '' . $ending; | |
| return $content; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment