Create invisible wordpress custom fields

June 2, 2009 · Print This Article

Many plugins use custom fields to store data about individual posts. When a plugin adds a custom fields, its key and value (or name and value) are listed in the Custom Fields meta box. For instance, a syntax hilighting plugin may set a custom field syntax_enabled on posts that use the syntax highlighting CSS.

Often the user doesn’t need to see this information and it can leed to needless confusion. Unless the user needs to edit these custm field values there’s really no need to have them listed here.

How to Hide Custom Fields

Custom fields can be hidden from the Custom Fields meta box quite easily. Typically custom fields are added by using the following code:

add_post_meta($id, 'name', 'value');

To hide your custom field from user view, simply start the name of your custom field with and underscore (”_”). So create your custom field like this:

add_post_meta($id, '_name', 'value');

Your custom field is now hidden.

Your choice for site templates and wordpress themes


One Response to “Create invisible wordpress custom fields”

  1. alexmglover on April 22nd, 2010 11:01 pm

    Can get_post_meta still be used to retrieve these values if the custom field is hidden from view… or is this trick simply used to keep the values from being displayed in the Custom Field box on the post/page?

Got something to say?

You must be logged in to post a comment.