Skip to content

Instantly share code, notes, and snippets.

@noahbass
Last active December 18, 2015 23:39
Show Gist options
  • Select an option

  • Save noahbass/5862967 to your computer and use it in GitHub Desktop.

Select an option

Save noahbass/5862967 to your computer and use it in GitHub Desktop.
Better WordPress Excerpts
<?php
// better WordPress excerpts
// Usage: echo get_excerpt(250); (replace 250 with the number of characters)
function get_excerpt($count) {
$excerpt = get_the_content();
$excerpt = strip_tags($excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = substr($excerpt, 0, $count);
$excerpt = rtrim($excerpt, '.');
$excerpt = rtrim($excerpt, ' ');
$excerpt = $excerpt.'...';
return $excerpt;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment