Adding Custom Field to WordPress Post

In WordPress there some default fields in add new post form. These are the title, HTML description, category, tags. If we want to add more information to our post, WordPress provides an option to enable custom fields.

This additional information added with the custom fields are called as post meta. This metadata is stored in the wp_postmeta table. In wp_postmeta table, each record represents the name and value of a custom field.

In this tutorial, we are going to see how to enable the custom field option in WordPress admin and how to get the custom field value and display them in a template file.

Enabling Custom Field Option in WordPress

In WordPress admin, we can enable Custom Fields checkbox under screen options menu. The figure shows the screen options menu.

After enabling this option let us add a custom field named as Website Reference to our post and add value to this field as shown in the figure.

Display Custom Meta Data in Post

WordPress provides various functions to access metadata and display them in a page template. The following function will display all metadata of a post in an HTML unordered list.