Categories
Websites WordPress

What is a WordPress Custom Field? How to implement it with steps

Want to know what WordPress custom fields are and easy steps to enable and add them?

This Online Business Consulting simplified guide on how to enable and add custom fields on WordPress sites got you.

Here's What a WordPress Custom Field is and the 3 easy steps to enable & add information to it

What is a WordPress Custom Field?

The WordPress custom field allow you to add metadata like meta descriptions, title tags, keyword tags, rich, structured data, etc.

The custom fields when enabled in the backend is visible on each page and post editor so you can input your metadatas information.

On the front-end your WordPress site visitors can see the datas.

Some of the metadatas like meta description and title tag can be displayed on Bing and Google Search result pages, etc.

Step 1: How to enable WordPress custom field

1. For WordPress site using Classic Editor:

  • login to your site page or post editor
  • Select the Screen Options tab at the top
  • Choose Custom Fields and click save

2. WP website using Block Editor:

  • Go to a page or post block editor
  • On the top right corner with three dots click the options icon to open the menu
  • Now click the Panels tab
  • Under Additional > Custom Fields check it Custom Fields
  • Click Enable & Reload next

That's it. Easy peasy!

Step 2: Adding custom fields

Adding custom fields once enabled on your WordPress site is easy:

  • When in your page or post editor, scrow down until you see the Custom Fields box
  • Click on Enter New to create a custom field
  • Name your custom field(keep it very short and descriptive) under Name
  • Input information in the Value box on the right side
  • Finally, click Add Custom Field to save

Once you added a custome field, you need add some code to display it on your site front-end so read below.

Step 3: How to add custom field code for meta description, keywords & title tag

Most WordPress site owners mostly use the custom field to enable and add WP built-in SEO features.

So those will be the WordPress custom field codes we will share in this section.

Here are some codes to enable and be able to customize meta description, keywords, and title tags.

Important

The codes below should be added to your function.php file or use the Code Snippets plugin(super easy to use and lightweight plugin) to add them.

Meta Description

/*Display custom meta description or the post excerpt */
function add_custom_meta_des(){

#Home, Single Page and Post Meta Description
if( is_single() || is_page() ){
	$des = get_post_meta( get_the_id(), 'description', true);
	if( ! empty( $des )  ){
		$meta_des = esc_html($des);
		echo '<meta name="description" content="' . $meta_des . '" />';
	}
}}	
add_action( 'wp_head', 'add_custom_meta_des', 1 );

Title Tags

/* Custom title tag function */
add_filter( 'document_title_parts', 'obc_custom_title');
function obc_custom_title( $title ) {
if ( ! is_singular() ) return $title;
$custom_title = trim(get_post_meta( get_the_id(), 'title', true ));
if( ! empty( $custom_title ) ){
	$custom_title = esc_html( $custom_title );
	$title['title'] = $custom_title;
	}
return $title;
}

Meta Keywords

/*Display custom meta keywords */
function add_custom_meta_key(){

#Home, Single Page and Post Meta Keywords
if( is_single() || is_page() ){
	$key = get_post_meta( get_the_id(), 'keywords', true);
	if( ! empty( $key )  ){
		$meta_key = esc_html($key);
		echo '<meta name="keywords" content="' . $meta_key . '" />';
	}
}}	
add_action( 'wp_head', 'add_custom_meta_key',2 );

Frequently asked questions:

Q: Why should I use custom fields?

A: It allows you to customize information as you see fit.

It also allows you to avoid slow plugins( to learn about WordPress slow plugins, see WordPress plugins to avoid), especially bloated all feature SEO plugins that do the same thing your WordPress custom fields can do.

It is always better to use the default WordPress custom field functionality without plugins.

That way you limit plugin security issues and adding a slow one(one of the great ways to improve websites speed is to limit or avoid slow plugins) .

Q: Are there some specific lightweight plugins to enable and add custom field info?

A: We understand that some people won't feel comfortable with adding codes to their WordPress site.

Here are some lightweight plugins your can use to enable the WordPress custom fields and customize it.

Custom Field Suite

Meta Box

Emmanuel Okeke

A Los Angeles resident who loves to write awesome guides on SEO, WordPress speed/security, content strategies, business and personal finance, digital and growth hack tools, legal stuff, etc, that are helpful to businesses, solopreneurs, bloggers, and consumers.

What I write about is based on tests, extensive research, and 11+ experience as a former Senior digital & content marketing consultant with a division of Thomson Reuters and running a successful digital marketing agency...[Read full bio]