X

Display Full Post or Just Excerpt Using Custom Fields

Snippets by IsItWP

Are you looking for a way to use a custom field value to define if a post is displayed in full or just the excerpt? While there’s probably a plugin for this, we have created a quick code snippet that you can use to display full post of just excerpt using custom fields in WordPress.

Instructions:

All you have to do is add this code to your theme’s single.php or index.php file or in a site-specific plugin:

<?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;
?>

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: How to create stunning WordPress optins and 10 best WordPress testimonial plugins.

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 Cancel reply

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!