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.
Sure this is supposed to be added to functions.php?
Whooops 🙂 updated this snippet. thanks for letting me know.