X

Display full post or just excerpt using custom fields

WP-PageNavi Review

Adding this snippet to the loop of your wordpress theme within single.php or index.php will let you use a custom field value to define if a post is displayed in full or just the excerpt.


<?php if (have_posts()) :
    while (have_posts()) : the_post();
         $customField = get_post_custom_values("full");
       	 if (isset($customField[0])) {
              the_title();
              the_content();
         } else {
              the_title();
              the_excerpt();
    endwhile;
endif;
?>

Comments  Leave a Reply

  1. Sure this is supposed to be added to functions.php?

    1. Whooops 🙂 updated this snippet. thanks for letting me know.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!