Title: Making custom fields required?
Last modified: September 16, 2022

---

# Making custom fields required?

 *  [station7](https://wordpress.org/support/users/station7/)
 * (@station7)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/making-custom-fields-required/)
 * Hi all,
 * I’m creating my first custom theme which includes a special layout section for
   post and page summaries.
 * I tried using the built-in post excerpt feature, but was frustrated to discover
   that it (Gutenberg) generates its own HTML that I can’t easily modify (specifically
   a P tag), so it’s not usable for what I want to do.
 * I decided to create a custom field instead, and the editors will just have to
   manually fill this in. I used this page as a guide: [https://wordpress.org/support/article/custom-fields/](https://wordpress.org/support/article/custom-fields/)
 * My custom field is called “Summary”. How can I:
    1. Restrict the number of characters
   editors can enter, and more importantly 2. How can I set this field to required
   so the editors don’t leave it blank?
 * I’ll be displaying the custom field as follows:
 *     ```
       <?php 
       	$post_id = get_the_ID();
       	echo get_post_meta($post_id, 'Summary', true);
       ?>
       ```
   
 * But I don’t want it to be blank
    -  This topic was modified 3 years, 8 months ago by [station7](https://wordpress.org/support/users/station7/).
      Reason: fix code
    -  This topic was modified 3 years, 8 months ago by [station7](https://wordpress.org/support/users/station7/).
      Reason: Figured out how to get the current page ID

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Jason LeMahieu (MadtownLems)](https://wordpress.org/support/users/madtownlems/)
 * (@madtownlems)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/making-custom-fields-required/#post-16017004)
 * Howdy,
 * This is covered in pretty great detail here: [https://wordpress.stackexchange.com/questions/42013/prevent-post-from-being-published-if-custom-fields-not-filled](https://wordpress.stackexchange.com/questions/42013/prevent-post-from-being-published-if-custom-fields-not-filled)
 *  Thread Starter [station7](https://wordpress.org/support/users/station7/)
 * (@station7)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/making-custom-fields-required/#post-16017223)
 * Hi Jason,
 * Thanks for the reply. I did find some stuff like that (very old answers), but
   as WP has changed so much in the last decade, is this still the right approach?
 * I was hoping I could do it within WP, but if I have to program something, I’d
   like to make sure it’s the most recent recommended way to do it. Thoughts?
 * Thanks!
 *  [Cheri Crystal](https://wordpress.org/support/users/chericrystal/)
 * (@chericrystal)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/making-custom-fields-required/#post-16023114)
 * Thanks your so much for providing the superb information. This is very helpful
   for me. I’m thankful to you.
 *  [Jason LeMahieu (MadtownLems)](https://wordpress.org/support/users/madtownlems/)
 * (@madtownlems)
 * [3 years, 8 months ago](https://wordpress.org/support/topic/making-custom-fields-required/#post-16023951)
 * >> I was hoping I could do it within WP, but if I have to program something, 
   I’d like to make sure it’s the most recent recommended way to do it
 * If you want to avoid coding it by hand, I would HIHGLY recommend looking at Advanced
   Custom Fields. This can support the Required functionality for you quite easily:
   [https://wordpress.org/plugins/advanced-custom-fields/](https://wordpress.org/plugins/advanced-custom-fields/)

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Making custom fields required?’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 3 participants
 * Last reply from: [Jason LeMahieu (MadtownLems)](https://wordpress.org/support/users/madtownlems/)
 * Last activity: [3 years, 8 months ago](https://wordpress.org/support/topic/making-custom-fields-required/#post-16023951)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
