Last active
April 21, 2018 09:29
-
-
Save janzikmund/9e191a18156f3c2210befdb630e8101b to your computer and use it in GitHub Desktop.
Get post excerpt out of the loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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