I have seen many asking how to insert custom Fields in WordPress post? Even though plugins are available nothing is a single-click solution.We need to do a bit of adjustments to make it work.Today I ended up doing that to improve the appearance and usability of my theme as it didn’t have those built in options.Since,I struggled a lot to make it work I thought of sharing it here.
Share
Here are the main steps:
Install the Custom Field Template.
Navigate to
Appearance > Editorand include this code snippet in yourfunctions.phpfile:Configure the custom fields by going to
Settings > Custom Field Template,expand the template content section, and add something like this:Note: Unless you add output = true, the custom fields won’t work.
Go to
Appearance > Editorand add this code into the template (such as single.php) where you want the value of the custom field to appear:To add a conditional statement around the getCustomField function (so that it only appears under certain conditions, such as the post being in a specific category), include this before the getCustomField function:
… then insert your getCustomField functions …
and then close with this:
Hope this helps you.