Plugins Plugin hub Backup SEO Caching Security Forms WooCommerce Images Best backup plugins
Hosting Hosting directory Shared hosting Managed WordPress Cloud hosting VPS hosting By reader location Hosting finder
Themes & builders Compare Rank Math vs Yoast
Tools All tools Hosting finder Plugin stack builder Cost calculator Salt generator Theme detector Who is hosting this? Speed test Headline analyzer robots.txt generator Redirect generator Uptime calculator Blog name generator
Blog Best backup plugins Deals
Guides All guides Speed up WordPress Choose hosting Back up WordPress
How we test

Developer · Guide

How to Add Custom Fields in WordPress

How to Add Custom Fields in WordPress

Short answer

To add a custom field in WordPress, open the post, switch on the Custom Fields panel, and add a name and value pair, or store it with add_post_meta() in code. Show the value in your theme with get_post_meta(), and register the field with register_post_meta() when the block editor or the REST API must read it.

Key takeaways

  • Custom fields store extra facts as name and value pairs in the postmeta table.
  • The Custom Fields panel needs a page reload and a toggle under Preferences.
  • add_post_meta() stores a value, and get_post_meta() reads it back in a template.
  • register_post_meta() with show_in_rest set to true exposes a field to the editor and the REST API.
  • A custom post type must support custom-fields before its fields can be used.
  • Escape field values with esc_html() before printing them on the front of the site.

What is a custom field in WordPress?

A custom field is a name and value pair that stores extra information about a post, page, or custom post type.

WordPress calls this data post metadata. Learn WordPress states that post metadata is stored in the postmeta table as key-value pairs, and the table has four columns: meta_id, post_id, meta_key, and meta_value (checked November 2026).

WordPress.org states that metadata is handled with key/value pairs, where the key is the name of the metadata element and the value is the information stored under it (checked November 2026).

The Plugin Handbook adds that metadata is information about posts, users, comments, and terms, and you can have as many meta options as you wish. Metadata is the handbook chapter that covers the idea (checked November 2026).

A custom field holds one kind of extra fact per item. A book post can carry an ISBN, an event post can carry a date, and a product post can carry a price. The title and the main content stay as they are, and the field adds the extra fact beside them.

You do not need a plugin to use custom fields. WordPress core stores the data, and the editor, the theme, and the REST API can all read it once it is set up right.

What do you need before you add custom fields?

You need an editor account, a post type that supports custom fields, and a short list of the key names you plan to use.

Posts and pages support custom fields out of the box. For a custom post type, Learn WordPress states that you must add or update the supports argument to include support for custom-fields (checked November 2026).

Pick your key names before you start. Use lowercase letters with underscores, such as book_isbn or event_date, and keep each name short and plain. A clear name saves confusion later, when the same key is read in a template or in the API.

Decide who will fill in each field. If editors type values by hand, the Custom Fields panel is enough. If the value must follow a set format, such as a date or a number, plan to register the field in code instead.

Adding one field by hand takes about a minute. Registering a field in code takes 15 to 30 minutes the first time, including a check that it saves and shows on the front of the site.

How do you add a custom field with the Custom Fields panel?

Open the post, switch on the Custom Fields panel, click “Enter new”, type a name and a value, then click “Add Custom Field”.

First, save the post, since the panel needs a page reload to appear. WordPress.org states that you should make sure your content is saved before you display the area, since a page reload is required for the option change (checked November 2026).

Next, open the editor Options menu, the three dots at the top right, and choose Preferences. Learn WordPress states that you then open Panels and enable the Custom Fields toggle, which refreshes the editor and shows the panel at the bottom of the screen (checked November 2026).

Note that the WordPress.org documentation describes the same toggle in a different place: under Preferences, then the General tab, in the Advanced section. The two pages describe different editor versions, so use whichever place your editor shows.

Then follow these steps:

  1. Scroll to the Custom Fields area at the bottom of the editor.
  2. Click “Enter new” to add a fresh field.
  3. Type the key name in the Name box, such as isbn.
  4. Type the value in the Value box, such as the book number.
  5. Click “Add Custom Field” to save it with the post.

Learn WordPress states that this panel uses the add_post_meta function to add the metadata to the post (checked November 2026). The value is saved when the post is saved.

You can reuse a key on the next post. WordPress.org states that the Name field will then offer a pull-down list with the custom fields you have used before, so you can pick the key instead of typing it again (checked November 2026).

One key can also hold more than one value on the same post. WordPress.org states that keys can be used more than once per post, so a post about two books can carry two “reading” values (checked November 2026).

How do you add a custom field with code?

Use add_post_meta() to store a value, update_post_meta() to change it, delete_post_meta() to remove it, and get_post_meta() to read it back.

Learn WordPress states that add_post_meta takes three parameters: the ID of the post, the name of the metadata, and the value of the metadata (checked November 2026). The lesson gives this example:

add_post_meta( 1, 'location', 'London' );

That line stores the value London under the key location for the post with ID 1. Learn WordPress names the other three functions for working with post meta as update_post_meta, delete_post_meta, and get_post_meta (checked November 2026).

Put this code in a small plugin if the field belongs to the site, not the design. Put it in the theme functions.php file only if the field belongs to that theme alone. A plugin keeps the data working when you change themes.

To pre-fill the Name box in the Custom Fields panel, use the postmeta_form_keys filter. Learn WordPress states that the filter passes two parameters, an array of meta keys and the post object, and fires before the panel HTML is rendered (checked November 2026).

Here is the shape of that filter, from the same lesson:

add_filter( 'postmeta_form_keys', 'bookstore_add_isbn_to_quick_edit', 10, 2 );

The callback checks the post type, adds isbn to the keys array, and returns the array. Editors then see isbn offered as a name when they edit a book.

How do you show a custom field value on your site?

Read the value with get_post_meta() in your theme template and print it with an escape function.

WordPress.org states that to display custom fields for each post, you have to use a template tag that customizes your theme, and it names the_meta(), get_post_custom(), and get_post_meta() for the job (checked November 2026).

A short template snippet reads the value and prints it safely:

$event_date = get_post_meta( get_the_ID(), 'event_date', true );
if ( $event_date ) {
    echo esc_html( $event_date );
}

Passing true as the third argument asks for one value. The esc_html() call keeps plain text safe for output, which matters when editors type the value by hand.

The same lesson shows a filter that appends a meta value to the post content.

The Block Editor Handbook uses get_post_meta() inside a the_content filter, then wraps the value in esc_html() before it is printed. Meta Boxes gives that pattern for showing a field at the end of the content (checked November 2026).

If you want a block to read the value instead of PHP, a guide on the Block Bindings API explains how blocks can show values stored as post meta.

To list every field on a post at once, use the_meta(). WordPress.org states that the_meta() is a template tag that automatically lists all custom fields of a post (checked November 2026).

How do you register a custom field for the block editor and the REST API?

Register the field with register_post_meta() and set show_in_rest to true, so the editor and the API can read and write it.

The Block Editor Handbook states that when you register a field, the show_in_rest parameter ensures the data will be included in the REST API, which the block editor uses to load and save meta data. Meta Boxes gives this registration example (checked November 2026):

function myguten_register_post_meta() {
    register_post_meta( 'post', 'myguten_meta_block_field', array(
        'show_in_rest' => true,
        'single' => true,
        'type' => 'string',
    ) );
}
add_action( 'init', 'myguten_register_post_meta' );

The same page states that your post type needs to support custom-fields for the register_post_meta function to work (checked November 2026). Without that support, the registration has no effect.

The REST API Handbook states that setting a meta field show_in_rest parameter to true exposes that field value on a .meta key in the endpoint response, and WordPress handles the callbacks for reading and writing it.

Modifying Responses covers both register_meta and register_rest_field for this job (checked November 2026).

Two version facts matter here. Modifying Responses states that as of WordPress 4.9.8, register_meta accepts an object_subtype argument that limits a meta key to one post type, and that WordPress 5.3 added support for the object and array types (checked November 2026).

For a custom post type, the post type must have custom-fields support or the meta fields will not appear in the REST API. Modifying Responses states that rule plainly (checked November 2026).

Add an auth_callback to guard writes. The WordPress meta-block example on GitHub registers its field with an auth_callback that returns current_user_can( 'edit_posts' ), so only users who can edit posts may change the value. WordPress Post Meta Integration with Blocks shows that registration (checked November 2026).

If the API response looks wrong, a guide on fixing the REST API error in Site Health walks through the checks that confirm the API is answering.

When should you use a custom field instead of a category or tag?

Use a custom field for a value that belongs to one item, and use a category or tag when you need to group or filter many items.

A price, a date, a subtitle, or an ISBN belongs to one post, so a custom field fits. A topic, a place, or a type groups many posts together, so a category or a tag fits better.

Fields also fit facts that need a set format. A date field can hold 2026-11-21, while a tag cannot tell the theme that the text is a date. Categories and tags hold names, not typed values.

Use one field per fact. A post with a start date and an end date needs two fields, such as event_start and event_end, not one field with both dates typed in.

What mistakes should you avoid?

Avoid renaming keys after launch, saving values with no type or permission check, and printing values without escaping them.

Do not rename a key once posts use it. Old posts keep the old key, and the template will read the new key and find nothing. If a name must change, update every post that uses it or keep the old key as well.

Do not skip registration for fields that editors change. An unregistered field still saves through the Custom Fields panel, but the block editor and the REST API cannot manage it in a set way.

Do not print a value straight from the database. Escape text with esc_html(), as the handbook examples do, and use the right escape function for URLs and attributes.

Do not hard-code colors or font sizes around field output in a template. Keep those choices in your theme settings instead, and a guide on how to use theme.json shows where those settings live.

FunctionWhat it doesWhen to use it
add_post_meta()Adds a new value under a keyFirst time you store a value
update_post_meta()Changes a stored valueEditing an existing field
get_post_meta()Reads one value or all values for a keyShowing the value in a template
delete_post_meta()Removes a value for a keyRemoving a field from a post
register_post_meta()Declares a field with a type and REST accessBlock editor or API use
Note: register the field before you build the block or the template that reads it, since the block editor loads and saves meta data through the REST API.

Frequently asked questions

Do I have to register a custom field before I can use it?

No. The panel stores the value in the postmeta table, and you can read it in a template with get_post_meta(). Registration is only needed when the block editor or the REST API must read or write the field, since those tools load meta data through the API.

Can I add custom fields to a custom post type?

Yes, but only when the post type supports custom fields. For a custom post type, add custom-fields to the supports argument when you register the type. Without that support, the panel stays hidden and register_post_meta has no effect.

Should I use a custom field or a category for this data?

Use a custom field when each post needs its own value, such as a price, a date, or an ISBN. Use a category or a tag when you need to group many posts under one name, such as a topic or a place, so readers can browse them together.

What happens if I rename a custom field key later?

Rename the key with care. Old posts keep the old key, so a template that reads the new key will find nothing on those posts. If a name must change, update every post that uses the old key, or keep the old key working beside the new one.

Can a headless front end read my custom fields?

Yes. Set show_in_rest to true when you register the field with register_post_meta(). The value then appears on the meta key in the REST API response, and the block editor can load and save it. The post type must also support custom-fields.

What is a good naming pattern for custom field keys?

Keep it simple. Use lowercase letters with underscores, such as event_date or book_isbn, and add a short prefix so your keys do not clash with keys from plugins. Pick the name before you fill in posts, and do not change it later.

Sources

  1. Custom post type data Learn WordPress
  2. Metadata WordPress Developer Resources
  3. Meta Boxes WordPress Developer Resources
  4. Modifying Responses WordPress Developer Resources
  5. Custom Fields WordPress.org
  6. WordPress Post Meta Integration with Blocks WordPress

Is your product missing, or something out of date?

Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.

About the editors

WPLegible editors

Researched from the primary sources listed above and checked against our editorial rules. About the site · How we test