Add, Delete and Edit Custom Fields in WordPress

Print View Mobile View
WordPress Logo

WordPress provides authors with a way to add additional information to a post/page by using custom fields. Custom Fields can be anything from defining an author of a post to setting an expiry date.

In this post, I will show how can add, delete and edit custom fields in WordPress.

Add Custom Field to a WordPress Post/Page

It’s quite easy to add custom fields to a post/page, and you might have already done it many a times.

To do so, simply find the “Custom Fields” meta box, and add a unique field name and any value you want. For example, here I will add a new custom field value of “author” to a post, which has “SumTips Admin” as it’s value.

Add Custom Field

Delete Custom Field Value of a WordPress Post/Page

There are three ways to delete a Custom field from WordPress, and all are shown here.

  • Delete Custom Field from all posts: Remove the custom field you want to delete by editing all posts containing it. Once there are no more posts containing a custom field, it is automatically deleted from the database.
  • From the database: Custom Field values can be deleted directly from the database. It’s a bit tricky, so make sure you backup the database before following this method.
  • Using a plugin: This method is the safest and fastest of all.

Delete custom field from database:

Login to phpmyadmin, and click on wp_postmeta in the left sidebar. Next go to Structure view, select meta_key and click on browse.

Delete Custom Field 1

Now you can see the earlier created author custom field.

Delete Custom Field 2

However you cannot delete the value here.

So, now click on the Search tab, enter author in the meta_key field and click on “Go.”

Delete Custom Field 3

This will give you a list of all the post which has author as a custom field.

Delete Custom Field 4

Here select all posts and click on drop to delete the custom field. Another option is to, select only those post from which you want to remove a particular field from and drop them.

Delete custom field using plugin:

An easier way is to use a plugin called Delete Custom.

Delete Custom

It gives you a simple interface to select and delete a Custom Field from a drop-down list.

Download: Custom Delete

Edit Custom Field of a WordPress Post/Page

To modify custom fields, follow the steps mentioned earlier, but instead of deleting this time click on “Change.”

Edit Custom Field

That will bring you to a page as below:

Edit Custom Field 2

Here change the value to anything you want and save it.

Hide Custom Field Metabox in WordPress Post/Page Edit Page

If you don’t use or don’t want the Custom Field Metabox, it can be easily removed by adding the following code to your functions.php file.

function remove_custom_meta_boxes() {
	remove_meta_box('postcustom','post','normal');
	remove_meta_box('postcustom','page','normal');
}
add_action('admin_init','hide_custom_meta_boxes');

Remove “post” or “page” line to keep the box in either.

Automatically Add a Specific Custom Field to all New WordPress Post/Page

add_action('publish_page', 'add_custom_field_automatically');
add_action('publish_post', 'add_custom_field_automatically');
function add_custom_field_automatically($post_ID) {
	global $wpdb;
	if(!wp_is_post_revision($post_ID)) {
		add_post_meta($post_ID, 'field-name', 'custom value', true);
	}
}

Replace the field-name and custom value with your Custom Field Name, and Value. via WPCanyon

2 thoughts on “Add, Delete and Edit Custom Fields in WordPress”

Comments are closed.