Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Limit words of a content
- * $post_id: pass the post id
- * $limit: int ( default 50 )
- * use: get_intro_text ( get_the_ID(), 100 );
- */
- function get_intro_text( $post_id, $limit = 50 )
- {
- $intro_text = get_the_content($post_id);
- $intro_text = preg_replace(" ([.*?])",'',$intro_text);
- $intro_text = strip_shortcodes($intro_text);
- $intro_text = strip_tags($intro_text);
- $intro_text = substr($intro_text, 0, $limit);
- $intro_text = substr($intro_text, 0, strripos($intro_text, " "));
- $intro_text = trim(preg_replace( '/\s+/', ' ', $intro_text));
- $intro_text = $intro_text.'... <a href="'.get_the_permalink( $post_id ).'">read more</a>';
- return $intro_text;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement