Custom fields are a handy WordPress feature that allows you to add various additional data/information to your WordPress posts and pages. Many popular WordPress plugins and designs use custom fields to store important data. You can also use custom fields to store your own data and then use it on your website.

How To Use Custom Fields Option In WordPress

What are WordPress Custom Fields?

Custom fields are an important and useful feature in WordPress and give us a very high level of customizability.

If you’ve reached WordPress by now, you probably already know that it’s a great forum to quickly put together a blog. Repeating the same information across multiple posts, especially on high content sites like blogs, can be time-consuming. You can get this job done faster with custom WordPress fields. The niche in WordPress has enabled strong customizability that allows it to meet the needs of nearly 30% of websites worldwide across all industries. If you use WordPress, you can create a simple blog or not ignore custom fields.

Word custom fields, on the other hand, are a source of controversy. Some argue that it delays requests while others argue that it is not suitable for scaling. To understand the facts, you need to learn more about the WordPress Custom Fields database and how to request data from it. Please be patient; we will gradually learn everything we need to know about them.

How do custom WordPress fields work?

WordPress custom fields are metadata that you can use to add additional details to the post or page you’re editing. When you create an article, blog, or other new content, WordPress stores it in two places by default. The main part of your content that you add using the post editor is the first part.

The second part provides details about the material in question. For example title, author, date, time, and other details. Metadata relates to the informational part of the message. WordPress will add all the necessary metadata to every post or page you create automatically. You can also use custom fields to create and save your own metadata.

What are the benefits of using custom WordPress fields?

  • Custom fields have the advantage that certain contact values ​​(customer number, account number, etc.)
  • Only account owners and administrators can add custom fields for stability.
  • Allows subcategories and inclusion of predefined values ​​for data integrity.
  • Automatically formats rankings on the front end of your site to create a stylish preview box.
  • Make sure all your review posts use the exact same format.
  • Use review ratings to request and sort content. For example, you can create a page that lists all the reviews that you have rated perfectly, or you can allow visitors to sort reviews by review rating.

How to use custom fields in WordPress

There are some ways to add custom fields to WordPress. One way is to use a plugin like Advanced Custom Fields. The second option is to use WordPress’ own features. It’s not that simple, but manual handling of custom fields means you have complete freedom with the metadata you include. Even if you’re using a plugin, knowing what’s going on behind the scenes is helpful.

Below we’ve shown you how to access and use this feature.

Enable Custom Fields option in WordPress editor

As previously mentioned, you usually need to enable custom fields in WordPress before you can see them. In the block editor, click the three-dot icon to open the settings menu: then select Options. This will open a popup window. Check the Custom Fields box, then click the Enable: Reload Post button. Under the editor, you will find the section User Defined Fields. Now that the WordPress custom fields feature is visible, it’s time to start adding metadata.

Add a new custom field

To create a custom field, click the Enter New option in the Custom Fields section. Then enter a name and value. For example, let’s say you just want to add a quick disclaimer to your sponsored post. You can go to the related Sponsored Posts field. In the Value field, you can enter specific metadata for the post you’re editing. In this case, a simple yes or no indication of whether the post is sponsored or not. Then click Add Custom Field to save this information (make sure to save or update the post yourself). Once you’ve done that, the same custom fields will be available to add to other posts or pages in the Name drop-down menu. This means that for each new post you simply select your custom field and enter the appropriate value.

Tell your theme how to display metadata in your custom field

When creating custom fields, you can add metadata to the back end. However, if you want to display this data on the front, you will need to edit the files for your active theme.

From your WordPress dashboard, go to Appearance > Theme Editor. You have to be very careful here because this section allows you to make changes directly to files on your site. Look for Single Post (single.php) in the right sidebar.

The single.php file contains the templates your theme uses for individual blog posts. Open it and look for the line /*Start cycle*/. The “loop” is the code WordPress uses to decide which blog posts to load for each page, based on how it’s been configured. We are not going to add the loops for your individual post templates but added a few new lines of code before the end. You can add any code you want to tell WordPress what to do with the data in your custom fields. For example, here is a snippet you can use:

<?php echo get_post_meta($post->ID, 'key', true); ?><?php endwhile; // end of the loop. ?><?php } ?>

Notice that there is a value that the key reads on the first line of code. This is the placeholder that you need to label with the name of the custom field you created in the first step. In our example this would be a sponsored post:

<?php echo get_post_meta($post->ID, 'Sponsored Post', true); ?>

This code tells WordPress to look for the sponsored post custom field and check its value. If this custom field is found for a specific post, its value will be displayed.