Skip to content

Instantly share code, notes, and snippets.

@mikeselander
Last active December 19, 2015 17:39
Show Gist options
  • Save mikeselander/5992640 to your computer and use it in GitHub Desktop.
Save mikeselander/5992640 to your computer and use it in GitHub Desktop.
Shortened get_the_content() with a passable character length variable. Defaults to 200 characters
function otm_short_content( $length = 200 ) {
$content = strip_shortcodes( strip_tags( get_the_content(), '<p><h2><h3><h4>' ) );
if ( strlen( $content ) > $length ){
echo wpautop( substr( $content, 0, strpos( $content, ' ', $length ) ) . "..." );
} else {
echo wpautop( $content );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment