Custom fields

ClassicPress has the ability to allow post authors to assign custom fields to a post. This arbitrary extra information is known as metadata. This metadata can include bits of information such as books you’re currently reading and your mood.

Assign custom fieldsLink to this section

Metadata is handled with key/value pairs. The key is the name of the metadata element. The value is the information that will appear in the metadata list on each individual post that the information is associated with.

Keys can be used more than once per post. For example, if you were reading two different books (perhaps a technical book at work and a fiction at home), you could create a “reading” key and use it twice on the same post, once for each book.

Here is an example of what this information might look like on your post:

Currently Reading: Calvin and Hobbes, The Da Vinci Code
Today's Mood: Jolly and Happy

UsageLink to this section

Based upon our example above, let’s add two custom fields, one called “Currently Reading” and the other “Today’s Mood”. Please follow the below steps to add this information to a post using custom fields.

  1. In the post editor navigate to the Custom Fields box. If this box is not displayed yet, enable the box via the Screen Options at the top of the screen.
  2. To create a new custom field called “Currently Reading”, enter the text “Currently Reading” (without the quotes) in the name field.
  3. The newly created key (“Currently Reading”) should now be assigned a value, which in our case is the name of the book currently being read, “Calvin and Hobbes”. Type “Calvin and Hobbes” in the value field, again without the quotes.
  4. Click the Add Custom Field button to save this custom information for that post.

To add your “Today’s Mood”, repeat the process and add “Today’s Mood” to the key and a description of your mood in the value text boxes and click Add Custom Field again to save this information with the post.

Custom Fields in Post Editor

On your next post, you can add a new book and mood to your metadata. In the Custom Fields section, the key will now feature a pull-down list with the previously entered custom fields. Choose “Currently Reading” and then enter the new book you are reading in the value. Click Add Custom Field and then repeat the process to add “Today’s Mood”.

You only need to create a new key once, after which you can assign a value to that key for every post, if you so desire. You can also assign more than one value to a key, for a post. This will come in handy for people who read more than one book at a time. Just select the key again and add a new value (book).

Display custom fields on the front endLink to this section

To display the custom fields for each post, you have to use a template tag that customizes your theme. There are multiple template tags (functions) that let you display custom fields and/or their values, but get_post_meta() is the modern standard.

ExampleLink to this section

To display the value of the “Currently Reading” key you could use this in your theme’s post template file, such as single.php:

if ( get_post_meta( get_the_ID(), 'Currently Reading' ) ) {
	echo 'Currently Reading: '.get_post_meta( get_the_ID(), 'Currently Reading', true );
}

 
This will return:

Currently Reading: Calvin and Hobbes

If you have multiple values assigned to the “Currently Reading” key, you could display all of them by using this:

if ( get_post_meta( get_the_ID(), 'Currently Reading' ) ) {
	echo 'Currently Reading: '.implode( ', ', get_post_meta( get_the_ID(), 'Currently Reading', false ) );
}

 
This will return:

Currently Reading: Calvin and Hobbes, The Da Vinci Code

 
Customize the code snippet to your needs (maybe add some HTML markup) and repeat this for any other keys you may have.

Note that if your key contains an apostrophe, like in “Today’s Mood”, you should escape the apostrophe by adding a backslash before, to avoid a fatal error. Like this:

get_post_meta( get_the_ID(), 'Today\'s Mood', true );

 

PluginsLink to this section

You could also install a plugin that manages custom fields by searching “custom fields” in the WordPress plugin repository. These plugins often let you add other custom field types as well, such as a text area or date/time input. There are no plugins in the ClassicPress Plugin Directory for this yet.

Last updated on November 27th, 2026 at 01:44 pm