Skip to content

Instantly share code, notes, and snippets.

@mikeselander
Last active December 21, 2015 17:08
Show Gist options
  • Save mikeselander/6338084 to your computer and use it in GitHub Desktop.
Save mikeselander/6338084 to your computer and use it in GitHub Desktop.
A companion function to the_short_content to return without any wpautop or echoing
function otm_get_short_content($length = 200) {
$content = strip_shortcodes( strip_tags( get_the_content(), '<p><h2><h3><h4>' ) );
if ( strlen( $content ) > $length ){
return wpautop( substr( $content, 0, strpos( $content, ' ', $length ) ) . "..." );
} else {
return wpautop( $content );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment