Advanced Custom Fields Review
Looking for an easy way to add and manage custom fields? Extended custom fields use the integrated functions of WordPress custom fields, but make them more accessible through a user-friendly interface.
Here you can learn how you can save time using custom fields with the Advanced Custom Fields plugin.
Why this plugin?
Custom fields allow you to add your own metadata to posts and WordPress pages.
A lot of modern plugins, such as Yoast SEO or Edit Flow, use custom fields to add data to your posts.
By creating your own custom fields, you increase control over what data is added and how it is displayed.
But default interface for WordPress custom fields is simply not suitable for users:
There is only a basic text field for work — you cannot upload images or enter other specific data types.
The Advanced Custom Fields (ACF) plugin uses the functionality of WordPress custom fields, but it creates a much more convenient graphical interface.
You can create custom fields that are displayed only for specific messages, categories, pages, custom message types, etc. And you can specify exactly what data can be entered in these fields, including:
- text
- numbers
- email addresses
- URLs
- Images
- files
- true / false
and much more
How to use Advanced Custom Fields
Install and activate the plugin, and you can go to the user fields »User fields to get started.
Click the Add New link at the top of the page to create your first group of fields.
Each custom field you create must belong to a field group. The field group determines when custom fields are displayed. Custom fields that are in the same field group will be displayed together.
For example:
- Need to use multiple custom fields for just one message category or just for your custom message type? They must be in the same group.
- Want to add a specific custom field to messages in one category, but another custom field for messages in another category? They must be in separate groups of fields.In our sample, we will add a GIF to every post in the “Cats” category.
Enter the name of the field group and click the Add Field button to add your first field.
In our sample, we will add a GIF for each message in the “Cats” category. Enter a field label and select a field type. In our example, we select “Image”. When you finish choosing your field options, you can close this field to collapse it. Just hover over the field name to edit or delete it.
Enter the name of the field group and click the Add Field button to add your first field.
In the “Location” section, select where you want to display custom fields in this group.
When you have selected all your options, click “Publish” on the right.
Now, when you edit a message, page or user mail that matches your chosen location, you will see your fields.
Display your data
The first step attaches this data to the message in your database, but it does not automatically display it on the site.
The data displayed with each message and page on your site is controlled by your theme files. This means that in order to display the new data you need to change the theme files.
The Advanced Custom Fields plugin has many built-in functions that make it easy to display your data.
To display your fields, you can use the function
the_field().
The function has two arguments:
the_field($field_name, $post_id);
$field_name:(required) name of the field to be received
$post_id: (optional) ID of the message where your value was entered (by default, the current message ID is used)
You specify the name of your field when it is created. To find it again, go to your group of fields, and it will appear at the top:
To display this field in our records, we can edit the single.php theme file and put this code where we want to display it:
the_field(‘kitten_gif’);