Skip to content

Instantly share code, notes, and snippets.

@lenivene
Last active February 26, 2016 06:09
Show Gist options
  • Save lenivene/ec6bcba5d73d632e0dd7 to your computer and use it in GitHub Desktop.
Save lenivene/ec6bcba5d73d632e0dd7 to your computer and use it in GitHub Desktop.
get_the_excerpt by ID post
<?php
/**
* Filter from "the_excerpt".
*
* @since 1.0.0
* @param string $post_excerpt The post excerpt.
*
*/
function get_excerpt_by_ID( $post = 0){
$post = get_post( $post );
if ( empty( $post ) ) {
return '';
}
if ( post_password_required() ) {
return __( 'There is no excerpt because this is a protected post.' );
}
return apply_filters( 'get_the_excerpt', $post->post_excerpt );
}
/**
* Filter the displayed post excerpt.
*
* @since 1.0.0
* @see get_excerpt_by_ID()
* @param string $post_excerpt The post excerpt.
*
*/
function the_excerpt_by_ID( $post = 0){
echo apply_filters( 'the_excerpt', get_excerpt_by_ID( $post ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment