WordPress Custom Fields is one of its most powerful features. In combination with Custom Post Types, they can convert WordPress to a Custom Application Building Tool, not only a CMS.
How to enable Custom Fields
Custom Fields (also known as metadata) are not enabled by default.
To enable them, press the “three dots” link in the Edit Post (or Edit Page) action and select Preferences.
Then, you can define custom fields and enter values. Unfortunately, the interface is poor. All values are inserted as text. You can modify this functionality, by writing custom code.
To display the field in the front end, you can use
- the the_meta() function to display a list of custom fields
- or the get_post_meta() to display the value of a certain field.
Advanced Custom Fields Plugin
However, instead of reinventing the wheel, you may use a plugin.
To display the field in the front end, it offers the get_field() function.
Remark: you don’t have to enable Custom Fields (see above) if you have installed the Advanced Custom Fields plugin. Moreover, the “Custom Fields” switch box is not visible in Preferences.
- WordPress Official Documentation – Custom Fields
- WordPress Plugins – Advanced Custom Fields
- Advanced Custom Fields – Official Website
- Advanced Custom Fields – PRO version – Official Website