Post Pic

WordPress tip: Create invisible custom fields

Existing Custom fields are visible and editables when you edit a post. But when the custom field is created by a piece of code, you may not want to display it publicly. Here is how to do.

This little trick is extremely simple: All you have to do is give a name starting with an underscore to your custom field when you create it, and it will not be displayed on WordPress dashboard when editing a post, as shown in the example below:

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

Easy, isn't it? And of course, very useful :)

Thanks to my friend John Kolbert for the tip!

19 Responses

May 26 2009 21:53

Awesome! It’s so simple. I’m searching this for a long time. Thank you very much.

May 26 2009 23:36

Don’t get the point. Could you give an example?

May 27 2009 00:37

Same here – I don’t get it either. Please explain a little bit further the reason behind this code. :)

May 27 2009 12:24

Nice tutorial, I love how this blog will write a tutorial for even the smallest of things!

What I think this does @Florian + @FreewareMatter is creates a custom field you can use in a post, but it won’t show up in the dropdown box on the post screen. So, I guess if you let guest posters or someone in the Admin Pane you don’t want to use the custom field, then this code won’t let them see it for use.

At least I think that’s what it’s for.

May 27 2009 16:32

So if you don’t see it, how to use it?

May 27 2009 18:28

Ya! this is really imformative code for wordpress user.

May 28 2009 19:57

Hey guys. I wrote the original tutorial, so let me elaborate. One way this could be useful is for plugin authors who create their own input boxes in the write post/page screens that interact with custom fields. For example, the Market Theme adds input fields for price, shipping, etc. that store their values as custom fields. By naming the custom field with the underscore it wouldn’t show up in WordPress’ custom fields editing box, but would show up in the input boxes created by the theme. It avoids the confusion of having the same info in two locations.

Jun 02 2009 08:50

Thanks John for the explanation. It was for those who loves to customize input fields and protecting them..err hiding them from wp system.

Jun 06 2009 18:15

Every time i try to put the code in either my post or my text widget it just comes up blank, it won’t show anything. Now widgetbucks say that you can post the code on your wordpress blog. However i am having issues doing so. Can someone please helpme and/or give me some tips.

Jun 07 2009 19:22

Plz let me know how u get it implement. Becoz I’m not getting it properly..

Jun 08 2009 07:46

What does this do actually?

Jun 08 2009 08:58

So simple and awesome..

Jun 10 2009 12:45

Now that IS handy, I’m still fairly new to WP development but I’m doing a lot of theme customisation for various projects at the moment. This is a useful tip, thanks.

Jun 17 2009 03:13

You right this is very easy! Nice and simple a great little trick. Its rare to see something that is both useful and easily done. That’s for the tutorial, and also for the explanation John!

Till then,

Jean

Jun 20 2009 13:57

Oh boy, let’s think, guys!

It’s useful specially when we have guest writers and they won’t be able to guess or use custom fields.

Its also handy to hide the fields you have been using in other posts – since wordpress stores it in a drop-down list.
All clear?

Aug 23 2009 08:57

simple but very usefull, thanks for the tips

Dec 22 2009 05:55

The developer I work with was trying to customize a plugin that touched on this and was looking for the best way to customize the look and feel of that link. This post was very helpful, I have already passed it along.

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required