Created
June 20, 2016 09:33
-
-
Save forrestbe/5edfee4dbd22eb0c66f7e5efc739b104 to your computer and use it in GitHub Desktop.
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
| function get_excerpt_by_id($post_id){ | |
| $the_post = get_post($post_id); //Gets post ID | |
| $the_excerpt = $the_post->post_content; //Gets post_content to be used as a basis for the excerpt | |
| $excerpt_length = 35; //Sets excerpt length by word count | |
| $the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images | |
| $words = explode(' ', $the_excerpt, $excerpt_length + 1); | |
| if(count($words) > $excerpt_length) : | |
| array_pop($words); | |
| array_push($words, '…'); | |
| $the_excerpt = implode(' ', $words); | |
| endif; | |
| $the_excerpt = '<p>' . $the_excerpt . '</p>'; | |
| return $the_excerpt; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment