Skip to content

Instantly share code, notes, and snippets.

View roryashfordbentley's full-sized avatar
🌭
Wranglin'

Rory Ashford-Bentley roryashfordbentley

🌭
Wranglin'
View GitHub Profile
function get_excerpt_by_id( $post_id, $charlength = 140, $ending = '[…]' ) {
global $post;
if ( $post->ID !== $post_id )
$post = get_post( $post_id );
if ( has_excerpt( $post->ID ) )
return $post->post_excerpt;
$subex = mb_substr( $post->post_content, 0, $charlength - 5 );
$exwords = explode( ' ', $subex );
$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
if ( $excut < 0 ) {