Wordpress Custom Excerpt Length

//add this to your functions.php function get_excerpt($count){ $permalink = get_permalink($post->ID); $excerpt = get_the_content(); $excerpt = strip_tags($excerpt); $excerpt = substr($excerpt, 0, $count); $excerpt = substr($excerpt, 0, strripos($excerpt, " ")); $excerpt = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $excerpt); $excerpt = $excerpt.' ...'; return $excerpt; } //add this where you want to call your excerpt - usually in your loop // the '50' signifies the character length of the excerpt - amend to your wishes. <?php echo get_excerpt(50); ?>
The wordpress excerpt just doesn't cut the mustard. With this snippet, you can now add a custom excerpt and specify how many characters you want to show. It also strips shortcodes so you dont need to worry about having your shortcode syntax showing up. Boom!

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.