Connect with us

How to Hide Your Plugin’s Custom Fields


How to Hide Your Plugin’s Custom Fields

This tutorial shows you how to keep your plugin’s custom fields from being manually edited in the post editor. Very handy, and it keeps things nice and neat!

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 highlighting 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 lead to needless confusion. Unless the user needs to edit these custom 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!

Continue Reading
Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

More in solution

    About Me:

    Szabi Kisded

    Hey there, I'm Szabi. At 30 years old, I quit my IT job and started my own business and became a full time WordPress plugin developer, blogger and stay-at-home dad. Here I'm documenting my journey earning an online (semi)passive income. Read more

    Sign up for my newsletter and get the YouTube Caption Scraper WordPress plugin for free
    (worth 29$)!

    All My Plugins In A Bundle:

    My AutoBlogging Plugins:

    My Online Courses:

    A Theme I Recommend:

    Featured Posts:

    To Top