How to use Advanced Custom Fields on WordPress
Advanced Custom Fields (ACF) allows you to add custom fields to your WordPress posts, pages, and custom post types through an intuitive interface. Install the ACF plugin, create field groups with your desired fields, assign them to specific content types, and display the data using ACF functions in your theme templates.
Prerequisites
- WordPress admin access
- Basic understanding of WordPress posts and pages
- Familiarity with WordPress themes
- Understanding of PHP basics (optional but helpful)
Step-by-Step Instructions
Install and Activate ACF Plugin
Advanced Custom Fields and click Install Now on the official ACF plugin by Elliot Condon. Once installed, click Activate to enable the plugin. You'll see a new Custom Fields menu item appear in your WordPress admin sidebar.Create a New Field Group
Add Fields to Your Group
- Field Label: The display name users will see
- Field Name: Auto-generated from the label, used in code
- Field Type: Choose from Text, Textarea, Number, Email, URL, Image, etc.
- Instructions: Optional help text for users
- Required: Toggle to make the field mandatory
Configure Location Rules
- Post Type: Show on posts, pages, or custom post types
- Page Template: Display only on specific page templates
- Post Category: Show on posts in certain categories
- User Role: Restrict based on user permissions
Set Field Group Options
- Style: Choose between "Seamless" (no metabox border) or "Standard"
- Position: Set to "High" to show fields near the top of the edit screen
- Label Placement: Choose "Top" or "Left" alignment
- Instruction Placement: Position help text above or below fields
Add Content Using Custom Fields
Display Fields in Your Theme
get_field('field_name') to retrieve values and the_field('field_name') to display them directly:<?php if( get_field('custom_text') ): ?>
<p><?php the_field('custom_text'); ?></p>
<?php endif; ?>For image fields, use:<?php
$image = get_field('custom_image');
if( $image ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>">
<?php endif; ?>Test and Refine Your Fields
Common Issues & Troubleshooting
Custom fields not appearing in post editor
Check your Location Rules in the field group settings. Ensure the rules match the post type, template, or category you're editing. Also verify the field group is published, not in draft status.
Fields showing empty values on frontend
Verify you're using the correct field names in your template code. Use get_field('exact_field_name') and ensure the field name matches exactly what's shown in the ACF interface. Check that the post actually has data in those fields.
ACF functions causing fatal errors
Wrap ACF functions in conditional checks: if( function_exists('get_field') ) to prevent errors if the plugin is deactivated. Also ensure you're calling ACF functions within the WordPress loop or with a specific post ID.
Field groups disappeared after theme change
Field groups are stored in the database, not your theme, so they should persist. Check Custom Fields > Field Groups to ensure they're still published. If missing, restore from a backup or check if they were exported as PHP code in your old theme's functions.php file.