Advanced Custom Fields - Extending WordPress Functionality Complete Guide
Mahesh Waghmare Advanced Custom Fields (ACF) is the most popular WordPress plugin for adding custom fields to posts, pages, and custom post types. It extends WordPress functionality without coding.
This comprehensive guide covers ACF from installation to advanced usage patterns.
Introduction to ACF
ACF allows you to add custom fields to WordPress content, creating structured data beyond default title and content.
Key Features:
- Visual field builder
- 30+ field types
- Conditional logic
- Repeater fields
- Flexible content
- REST API support
Use Cases:
- Product information
- Event details
- Team member profiles
- Custom metadata
- Structured content
- Headless WordPress
Installation and Setup
Installation
Method 1: WordPress Admin:
- Plugins → Add New
- Search “Advanced Custom Fields”
- Install and Activate
Method 2: Manual:
- Download from advancedcustomfields.com
- Upload to
/wp-content/plugins/ - Activate in WordPress admin
Initial Setup
- Create Field Group: Custom Fields → Add New
- Add Fields: Click “Add Field”
- Set Location Rules: Where fields appear
- Publish: Save field group
Creating Custom Fields
Basic Field Creation
Steps:
- Go to Custom Fields → Add New
- Add Field → Enter field label
- Choose field type
- Configure field settings
- Set location rules
- Publish
Field Configuration
Common Settings:
- Field Label: Display name
- Field Name: Internal name (slug)
- Field Type: Text, Image, Select, etc.
- Required: Make field mandatory
- Default Value: Pre-fill value
- Instructions: Help text
Location Rules
Set where fields appear:
- Post types (Posts, Pages, Custom)
- Page templates
- User roles
- Taxonomies
- Options pages
Field Types
Text Fields
- Text: Single line text
- Textarea: Multi-line text
- Number: Numeric input
- Email: Email validation
- Password: Hidden input
- URL: URL validation
Content Fields
- WYSIWYG: Rich text editor
- Image: Image upload
- File: File upload
- Gallery: Multiple images
- OEmbed: Embed media
Choice Fields
- Select: Dropdown
- Checkbox: Multiple selection
- Radio Button: Single selection
- True/False: Boolean
Relational Fields
- Post Object: Link to post
- Page Link: Link to page
- Relationship: Multiple posts
- Taxonomy: Link to taxonomy
- User: Select user
Layout Fields
- Group: Organize fields
- Repeater: Repeatable fields
- Flexible Content: Layout builder
- Clone: Reuse field groups
Displaying Field Data
In Templates
Basic Usage:
$value = get_field('field_name');
echo $value;
With Post ID:
$value = get_field('field_name', $post_id);
In Loop:
while (have_posts()) {
the_post();
$custom_field = get_field('field_name');
echo $custom_field;
}
Field Functions
get_field(): Get field value
$value = get_field('field_name');
the_field(): Display field value
the_field('field_name');
get_field_object(): Get field configuration
$field = get_field_object('field_name');
have_rows(): Check for repeater rows
if (have_rows('repeater_field')) {
while (have_rows('repeater_field')) {
the_row();
$value = get_sub_field('sub_field');
}
}
Advanced Features
Repeater Fields
Create repeatable content:
if (have_rows('team_members')) {
while (have_rows('team_members')) {
the_row();
$name = get_sub_field('name');
$role = get_sub_field('role');
// Display...
}
}
Flexible Content
Layout builder:
if (have_rows('content_blocks')) {
while (have_rows('content_blocks')) {
the_row();
$layout = get_row_layout();
if ($layout == 'text_block') {
// Text block template
} elseif ($layout == 'image_block') {
// Image block template
}
}
}
Conditional Logic
Show fields based on conditions:
- Field value equals
- Field value not equals
- Field contains
- Field is empty/not empty
Options Pages
Global settings:
$logo = get_field('site_logo', 'option');
$phone = get_field('contact_phone', 'option');
Best Practices
1. Use Descriptive Field Names
// Good
get_field('product_price');
// Bad
get_field('field_1');
2. Set Default Values
Provide sensible defaults for better UX.
3. Use Field Groups
Organize related fields into groups.
4. Validate Input
Use ACF validation or custom validation.
5. Document Fields
Add instructions to help content editors.
Conclusion
ACF extends WordPress by:
- Adding custom fields easily
- Structuring content beyond defaults
- Creating flexible content layouts
- Enabling headless WordPress
Key Points:
- Visual field builder
- Many field types available
- Easy to display in templates
- Supports complex layouts
- Essential for custom WordPress development
ACF is essential for extending WordPress functionality and creating custom content structures.
Written by Mahesh Waghmare
I bridge the gap between WordPress architecture and modern React frontends. Currently building tools for the AI era.
Follow on Twitter →