A Guide to WordPress Custom Fields

When you write a post/content on your blog, in you post writing page you will see the fields for entering  title and body content. If you take a look at the WordPress post writing page you’ll notice a section below the post content text area is titled Custom Fields.

custom fields

custom fields

What if I don’t see Custom Fields section in post writing page?

There’s a chance you won’t see this feature. If not, look to the top right of your window and click Screen Options.

Screen Options

Screen Options

From there make sure the Custom Fields option is selected.

select custom fields

select custom fields

Once selected you should see it at the bottom of your screen like I have above.

Custom fields

Custom fields allow you to add little bits of data to posts. The custom fields section contains two input fields labelled Name and Value. The key identifies the specific field and the value is the information that will be displayed.

For examples if you are writing a post about a tourist place you can add Custom field like “Today’s Weather”, and then add the value “Sunny”.

custom fields

custom fields

This extra information is known as meta-data. Now this information related to your post can be displayed anywhere within your WordPress theme.

Make your Theme ready with Custom Fields

Custom fields don’t display by default unless your theme has been customized to do so. In order to get these values to display we need to add a small amount of PHP to our WordPress loop function inside our theme’s code. Let’s do that now.

To start you’ll need a code editor and access to your theme directory which is located at wp-content/themes/themename.

Open single.php file inside a code editor. Find where your main WordPress Loop starts.

WordPress Loop  starts

WordPress Loop starts

Add this code inside the WordPress loop to display all custom fields associated with that post.

Call the_meta()

the_meta()

the_meta” function will display all fields associated with that post.If you have 10 different fields that you want to display at 10 different locations, then we will have to use “get_post_meta” function.

 use get_post_meta hook

use get_post_meta function

Web Hosting

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

*