How to Create Custom Fields in WordPress

What IS a custom field in WordPress? If you’re not familiar with custom fields, you may want to take a peak at the WordPress Codex. In short, a custom field is a bit of meta-data attached to any page or post in your WordPress site. It’s stored in a key/value format and can be useful for assigning bits of uniform data across multiple posts.

Whut?

I’m going to give a quick usage scenario for a custom field and then share a few links to get you thinking about the wide world of possibilities when it comes to using custom fields in WordPress.

Create that Custom Field

Scenario: Custom Field in Action

Let’s say you’re a travel blogger and you’d like to assign a location to each of your posts. Of course you could include your location as part of your post content, but where’s the fun in that? Maybe you want to use the location name as a design element on the page – wouldn’t it be nice to have style control over that specific piece of meta-data?

Of course it would!

How to Add a Custom Field to a Post

First things first: When in your post editor screen, make sure you have the Custom Fields option checked.

Screen Options - Custom Field

Once that’s done, you’ll see the Custom Fields box as part of your post editor:

Custom Field

Okay, now you’re ready, little travel blogger! For this example, we want the Name of our Custom Field to be Location. The Value is going to be wherever your travels had you for this particular post. Since I’m writing from my home city today, I’ll set the value to Fort Worth, TX.

Note: The first time you add a Location, you’ll have to use the “Enter new” link in the Custom Fields window. In every subsequent post, Location will be in the drop-down menu.

I hope the Location on my next post is Hawaii.

Onward and Outward

Okay, so that’s the briefest of introductions. Check up on the links below to see additional ideas and usage scenarios for custom fields. They are limitless!

Other cool uses for Custom Fields

Here are some other great posts that discuss uses for custom fields:

Extend WordPress with Custom Fields (Smashing Magazine)

Advanced Uses for Custom Fields (screencast by Chris Coyer)

Really want to stretch your brain?

This is a great article to get you started on understanding how custom fields can work in beautiful harmony with custom post types and taxonomies.

WordPress Custom Fields vs. Custom Posts Types vs. Custom Taxonomies (WPMU)

Comments

  1. says

    This is so timely… While I’ve known of custom post fields (and have used them on other sites I contribute on) and custom post types, I’m finally forcing myself to learn to use them (at least, that’s what I tell myself!!) This is a big help — thank you!

    I’m really trying to grasp custom post types. This right-brained girl’s eyes glaze over before ending paragraph one in most ‘how-to’s. Maybe that will be an upcoming post? ;)

    • Carrie Dils says

      Glad to hear it! Yeah, I’ve been working with CPTs more lately and absolutely digging the way it extends WordPress. I’m using the WP-Types & Views plugins (there’s a link in my footer, I think) that has taken some of the learning curve out of CPTs and actually helped me understand them better. Sounds like a good topic for an upcoming post, indeed. :)

      • says

        Back again, after thinking on this more :)

        I’m trying to create a custom page that lists contributors for a site. I’ve found no easy way to pull in the info from the user profiles (I’ve found one… but wow — over my head)

        So I’m wondering if custom post type and custom fields might work in the situation instead? What do you think? I am still misunderstanding how to use them?

        • says

          (that should say AM I still misunderstanding, although, I think I could make the statement that I am :)

          also: That plugin looks great! If I end up purchasing, I’m using your affiliate link because you/your site is super helpful.

          • Carrie Dils says

            I appreciate that! In the interest of disclosure, I’ll tell you that I had some problems when I migrated a site to a new URL that was using the Types/Views plugin. Don’t know if it was a fluke or a bug, but it cost me time to fix and was annoying. While it IS a very cool tool, I think it has some room for improvement, especially considering it’s $40 bucks. When I pay for a premium plugin, I don’t want bugs. :) The support forums are decent though. Just FYI!

        • Carrie Dils says

          How many contributors are you talking about? The simple solution might be a regular ole page with some copy/paste action.

          First part of the puzzle is to make sure all your info is “grouped” together for your contributors (if I’m understanding correctly, this is where your custom fields question comes in):

          1) Where are you pulling user profiles? Your site?
          2) Do those profiles contain all the pertinent info already or are you wanting to add to it (i.e. Favorite Color)? If not, this is where adding fields to the user profiles might be adequate. There are some plugins out there that’ll let you extend user profiles with extra fields – no code required.

          Second part of the puzzle is the output or display of all this great info. That’s where a custom page template can come in.

          • says

            It’s about 14 right now… and could grow. I’m good with copy and paste if that is the best solution. But would custom fields help keep everything formatted the same for each contributor?

            1) User profiles pulled from bio. But maybe it’s entered/pasted into custom fields too, in order to make this work.
            2) it would be name, bio, twitter, facebook, pinterest, website…

            *head explodes* lol

Trackbacks