When you create a new blog post in WordPress, you’ll notice information such as author name, time, date and other details on your post.
These are called metadata, and WordPress automatically adds them to every page and post on your website. You can create your own metadata by adding custom fields in WordPress.
Custom fields and metadata are particular tools needed by developers for themes and plugins to expand the functionality of WordPress.
Nonetheless, they can be used for general purposes such as adding affiliate disclosure or sponsored content to WordPress posts.
This guide will show you how you create and add custom fields in WordPress using 2 different methods.
- Frequently Asked Questions
- What You’ll Need to Add a Custom Field in WordPress
- How to Add Custom Fields in WordPress: 2 Methods Explained Step by Step
- Method 1: How to Add Custom Fields in WordPress Manually
- Method 2: How to Add Custom Fields in WordPress Using Plugins
- Wrapping Up
- More Helpful WordPress Tutorials:
Frequently Asked Questions
What is a Custom Field in WordPress?
A custom field is an advanced part of WordPress development. This feature allows you to add extra details to your post and pages.
Instead of having to repeat the process of adding the same information to individual posts or pages, you can create a custom field to add it.
The information you add is called metadata. Just like the title, author, date, and time are default metadata in WordPress.
Can I Add Custom Fields in WordPress Without a Plugin?
Yes. You can add a custom field in WordPress without a plugin.
While the process might appear somewhat advanced, it’s more straightforward than you think. We’ll show you how in this post.
What You’ll Need to Add a Custom Field in WordPress
WordPress Admin Access: You need access to the WordPress admin dashboard.
Without an Admin or Super Admin role in WordPress, you can’t add a custom field to posts or pages.
A Custom Field Plugin: You can use several free and paid plugins to add custom fields in WordPress.
We’ll show you to use the famous Advanced Custom Field Plugin, which is used by over 2 million websites.
How to Add Custom Fields in WordPress: 2 Methods Explained Step by Step
There are two ways you can add a custom field in WordPress;
Method 1: Adding Custom Fields Manually
- Step 1: Enable Custom Field in WordPress
- Step 2: Add Custom Field to a Post or Page
- Step 3: Adding Custom Field Code to WordPress Theme File
Method 2: Using a Custom Field Plugin
- Step 1: Install Advanced Custom Field Plugin
- Step 2: Add a New Field Group and Input Your Custom Field Details
- Step 3: Configure Custom Field Display
However, many users prefer using the WordPress built-in functionality because it gives them flexibility and control over their metadata.
Also, the benefit of not adding an extra plugin because of a single function makes adding custom fields manually worth it.
Note Regarding This Method:
We’ll start by showing you the manual process.
This method requires you to edit the WordPress theme file. You need to create a backup of your site before attempting it.
So you can restore your site if anything goes wrong. Create your custom field on a staging site before deploying it on your live site, if possible.
Method 1: How to Add Custom Fields in WordPress Manually
The custom fields feature is default hidden in WordPress since it’s an advanced feature.
To use a custom field on your WordPress post, you must first find and enable it. That’s step 1.
Step 1: Enable Custom Field in WordPress
The WordPress block editor will open.
Click on the three-dot icon at the top right corner to open Settings and select Preferences at the bottom.
On the popup window, switch to the Panel tab and toggle on the Custom fields radio button.
You’ll be prompted to reload the page to enable custom fields.
If you are doing this on a post with content, make sure you save your post before reloading the page. We recommend doing this on an empty page.
Click on the Enable and Reload button.
The post editor page will reload, and you’ll see the Custom Fields panel below the block editor.
That’s it. You’ve successfully enabled custom fields in WordPress.
Henceforth, anytime you need to add a custom field to a post, you only need to fill the section with the right name and value, as it will be stated in your theme file. You’ll see how to do that soon.
The next step in adding a custom field in WordPress is adding it to the page or post where you want it to appear. That’s step 2.
Step 2: Add Custom Field to a Post or Page
Here, you’ll edit the post or page you want to add a custom field.
We’ll be using a post to show you how.
Go to your Post Page on WordPress, choose a post to which you want to add a custom field, and click Edit.
Once the post opens, scroll to the custom field section.
Depending on the theme or plugin on your website, there may be some options already listed in the Name field.
Neglect all and click on Enter New.
Next, enter the Name and Value for your custom field inside the meta box and click the Add Custom Field button to save your settings.
You can use any name and value you like.
For this tutorial, we’ll add Affiliate Disclosure in the Name box and this sentence as the value: Sponsored Post: This post contains affiliate links. We might earn a commission if you make a purchase using these links.
Your metadata will be stored and displayed as in the screenshot below.
You can update and delete your custom field anytime. You can also add a new custom field.
Once you are done, remember to save the post you are editing.
So far, you’ve enabled a custom field in WordPress and added a name and value to your metadata.
But you are yet to tell your site to display the custom field. We’ll do that next.
Step 3: Adding Custom Field Code to WordPress Theme File
This step requires you to edit your WordPress theme file.
Again, we advise creating a backup of your site before you proceed.
You’ll be dealing with a bit of code here. But there’s nothing to be afraid of.
Just follow the steps closely. The process is pretty simple. Let’s go.
On your WordPress dashboard, navigate Appearance and select Theme File Editor.
In the right-hand sidebar under Theme Files, locate Single Post (single.php) and click to open.
The single.php file contains your theme’s code for displaying individual blog posts.
You don’t need to tamper with anything inside the file. We’ll only add a code snippet.
Here’s an example of WordPress’s most commonly used snippets for adding custom fields.
<?php echo get_post_meta($post->ID, ‘key’, true); ?>
Note the key in the code above is the name of the custom field you set in step 2. The Value should be set to true to display your message.
Thus our custom field code will look like this.
<?php echo get_post_meta($post->ID, ‘Affiliate Disclosure’, true); ?></p>
That’s the code we’ll add to the theme file. Where you place, this code will depend on where you want your custom field to appear on your site.
For this tutorial, we’ll put this code on top of the WordPress loop code, as in most affiliate sites. The line looks like this.
<?php while ( have_posts() ) : the_post();
Once you add the code, click the Update File button to save the changes and reload the post.
This code snippet tells WordPress to search for the post with Affiliate Disclosure custom fields and display the value.
WordPress will not display anything if the value is not set to true.
This is what it looks like when the message is displayed.
Now you can use this custom field for any of your WordPress blog posts.
When creating a new post, simply scroll to the custom field panel, choose your custom field from the list and enter its value.
You can use as many values as you like for the same custom field name.
The example above is one of the most basic uses of WordPress custom fields.
To perform advanced actions with custom fields in WordPress, the code will vary depending on the information you want to display.
You can learn more about custom fields in WordPress codex.
Method 2: How to Add Custom Fields in WordPress Using Plugins
If adding custom fields manually is too complex a process, you can embrace the simplicity of custom field plugins.
The most popular of all is the Advanced Custom Fields plugin.
This super intuitive plugin allows you to add up to 30 custom fields in WordPress with just a few clicks.
Let’s see how to use the Advanced Custom field plugin.
Using Advanced Custom Fields Plugin step by step
To get started, you first need to install the plugin and activate it. Here’s how.
Step 1: Install Advanced Custom Field Plugin
Log in to the WordPress dashboard, hover over Plugins in the left panel and select Add New from the option.
This will take you to the plugin page. Type Advanced Custom Fields into the search box.
Once you find the plugin, click on Install now. Wait for the installation to complete, then click the Activate button.
Done! You are now ready to use Advanced Custom Plugin.
Step 2: Add a New Field Group and Input Your Custom Field Details
A field group is a collection of custom fields. You can add multiple custom fields to a WordPress post or page with one field group.
Go back to your WordPress dashboard, locate Custom Fields on the left panel, and click on Field Groups.
Use a descriptive name for your New Field Group title, then click the Add Field button to add your first custom field to the group.
You’ll need to input your Field type, Label, Name and Default Value.
Advanced custom fields allow you to add all kinds of fields, Text, Button Groups, checkboxes, emails and more.
Click on the Field Type dropdown and select the custom field type you want.
Say we want to create a custom field that requests authors’ byline. We’ll set the Field Type to Text since the information we want to collect is Text.
Once you add the Field Label, your Field Name box will be automatically updated with the same details.
You can change this if you like. Just make sure you follow the instruction under the field.
You can use the same name in the default value. This will appear when creating a new post.
After filling in the details, click the Close Field button at the bottom.
To set the field as required for all authors, switch to the Validation tab and toggle on the radio button next to Required.
Authors can’t publish the post without inputting the required information. You can also set the Character limit on this page.
To add instructions to the custom field, switch to the Presentation tab and type in your instructions.
We add, “Please enter your byline with a link to your LinkedIn profile before publishing this post.”
You can add placeholder text to the field and even Prepend and Append text to the author’s input.
There are other features like conditional logic and wrapper in Advanced Custom Field plugins. You can play around with them to get the full grips of how they work.
Once you are done setting up the basic details, scroll down to the Close Field button and click on it. Your custom field will be added to the field group. To add more custom fields, follow the same steps.
Step 3: Configure Custom Field Display
Now that you are through creating your custom field, you need to determine where you want it to appear. To do this, go to the Settings section on the page.
On the Location Rules tab, you’ll see an option labelled Show this field group if.
There’s a list of locations you can choose from. Select where you want your custom field to appear from the list.
In our example, we’ll leave it as Post Type. With this, our custom field will appear on all regular posts created on our website.
Use the Add Rule Group button to display this same custom field in more than one location.
To customise the appearance of your custom field, you can switch to the presentation tab and edit the Style, Position and Placement.
Once you are done, click the Save Changes button at the top of the page to apply your settings.
Open your WordPress post editor to verify that your setting has been saved. You’ll see the custom field section below the editor.
That’s all! You’ve successfully learnt 2 ways to add custom fields in WordPress.
While using the Advanced Custom Field plugin is simple, be informed that you can’t add custom fields for your visitors. You can only use it for displaying custom fields in your dashboard.
You can only use the manual method to display custom fields your website visitors will see.
We’ve explained both methods in detail, and you should be able to add custom fields without hassle using either method.
Have questions or suggestions on custom fields? Drop us a line in the comment section.
More Helpful WordPress Tutorials:
- How To Add Custom CSS In WordPress: Take control of your WordPress website appearance by learning how to use CSS codes. Customise the look and feel of WordPress with the steps in this guide.
- How to Fix Common WordPress Bugs: Are Bugs plaguing your WordPress website? You are not alone. This comprehensive guide will walk you through the steps for fixing common WordPress bugs.
- How to Add Schema Markup to WordPress: Schema markup is not difficult to implement in WordPress. You’ve just not come across a detailed guide. This tutorial is all you need.