Skip to content

Instantly share code, notes, and snippets.

@cameronjonesweb
Created October 23, 2021 00:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronjonesweb/220708af0071526600d0a3df843eedea to your computer and use it in GitHub Desktop.
Save cameronjonesweb/220708af0071526600d0a3df843eedea to your computer and use it in GitHub Desktop.
Get the excerpt of a post by ID, and generate one if not set manually
<?php
/**
* Get the excerpt of a post by it's ID
*
* @param int $post_id Post ID.
* @return string
*/
function cameronjonesweb_get_excerpt_by_id( $post_id ) {
return apply_filters( 'get_the_excerpt', wp_trim_excerpt( get_post_field( 'post_excerpt', $post_id ), $post_id ), $post_id );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment