Skip to content

Instantly share code, notes, and snippets.

@janzikmund
Last active April 21, 2018 09:29
Show Gist options
  • Save janzikmund/9e191a18156f3c2210befdb630e8101b to your computer and use it in GitHub Desktop.
Save janzikmund/9e191a18156f3c2210befdb630e8101b to your computer and use it in GitHub Desktop.
Get post excerpt out of the loop
<?php
// get excerpt out of the loop
function my_excerpt($post_id) {
$post = get_post($post_id);
if ($post->post_excerpt) {
// excerpt exists, return it
return apply_filters('the_excerpt', $the_post->post_excerpt);
} else {
setup_postdata( $post );
$excerpt = get_the_excerpt();
wp_reset_postdata();
return $excerpt;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment