Blog

WordPress Custom Fields

By:
on:

WordPress Custom Fields can be really handy when you want to add some custom metadata to a specific part of your template. For example, you can use it to add a classname to a div, or merely to add some extra info. The convenient part is that you can give the value to each post or page separately.

Here's how you do it...

First we'll add this code to our template (for example single.php).



In this example I'm using "appsaloon" as ID of the custom field.

Let's say I would like to put the code inside a div and H1 tag, like this...

 

 

 

You can style it with CSS the way you want.

Now I'll tell you where to put in the value, login to the WordPress backend.

Choose to add or edit a post or page.

Now this is really important, it might be possible that the custom fields are not enabled yet.

At the very top of the page you will see "Screen Options"; click it.

You'll be able to view some extra options, just check "Custom Fields" and it will be added at the bottom of the page as shown on the screenshot below.

In the "Name" field you'll add the ID,

now just add the value you want and click "Add Custom Field".

customfield

If you are editing an existing post or page, don't forget to update!

This is the HTML that will be created...

 

 

 

One more thing I would like to show you is how to display the custom field, only if it exists.

Which is a pretty logical thing to do.

 

 

 

Now try it yourself, good luck!

KOEN IS HAPPY TO INTRODUCE APPSALOON
APPSALOON BV
Bampslaan 21 box 3.01
3500 Hasselt
Belgium
VAT: BE08 4029 5063
2021 © AppSaloon All Rights Reserved
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram