Including the HTML code of any field inside a <p></p> HTML tag, we can easily take advantage of the WordPress standard CSS for admin environment. All fields will be perfectly distributed inside the metabox, they keep the margins, paddings, etc. without any additional CSS rules. But, let’s go with the examples.

A regular INPUT

If you want, you can change the value of the attribute type for introducing, instead of a simple text, also an email, or an url, a password, a number, etc… But, be carefull with the value date, time or similars because the field doesn’t works (extending a selector for years/month/day) in all browsers.

Remember that, if you want you can also use just the type text for the field in combination with the corresponding WordPress escape functions applied to the value. See the next example for an URL field.

It produces the same result but, using text for the attribute type, it is avoided the browser checking of the field so that, we can introduce our own checking routines, for example, during saving process, or via an AJAX call, etc.

Textarea

It’s very important to use an escape function, always that you want, for example, to allow HTML tags inside the textarea field.

Expertise Levels

Programming Languages

What about the author?

Joan Miquel Viadé

Barcelona, 1966, I begin in the world of computer hand in hand with IBM in 1988 where I work for a year and a half. Later I am studying computer engineering and I graduate in 1994. Since then I participate in various computer projects until in 2010 I begin to specialize in projects based on the WordPress technology. See full bio.