How to Build a Custom Settings Page ACF


Custom Settings Page for ACF is a powerful feature that allows developers to create tailored admin options for WordPress themes and plugins. By leveraging Advanced Custom Fields, you can efficiently design settings pages with dynamic fields like text inputs, dropdowns, and checkboxes, all while maintaining a user-friendly interface.

Many found our in-depth article on Advanced Features of ACF Copilot Every Developer Should Know to be helpful as well.

What is a Custom Settings Page?

A custom settings page is an admin section in WordPress where users can configure specific options for a theme or plugin. These pages provide flexibility beyond WordPress defaults, and ACF makes creating them efficient and user-friendly.

Why Choose ACF for a Custom Settings Page?

ACF simplifies the creation of settings pages, reducing development time. With ACF, you can:

  • Add text fields, dropdowns, and checkboxes.
  • Manage field groups for a structured admin area.
  • Integrate seamlessly with the WordPress dashboard.

Adding a Custom Options Page with ACF

For creating a settings page in ACF, the Pro version simplifies the process:

  1. Go to Custom Fields > Options Pages.
  2. Click Add New Options Page.
  3. Add a page title, menu title, and unique menu slug.
  4. Save the page to use it in your admin menu.

If you use the free version of ACF, register the page manually with code:

if( function_exists('acf_add_options_page') ) {
    acf_add_options_page(array(
        'page_title'    => 'Custom Settings',
        'menu_title'    => 'Custom Settings',
        'menu_slug'     => 'custom-settings',
        'capability'    => 'edit_posts',
        'redirect'      => false
    ));
}

Creating Field Groups for ACF

Field groups define the input options for your settings page. To set one up:

  • Go to Custom Fields > Field Groups and click Add New.
  • Name the group and add fields like text or checkboxes.
  • Assign the field group to the options page you created.

Displaying Custom Settings on the Frontend

Use ACF’s get_field() function to retrieve field values and display them on your site:

Many found our in-depth article on Advanced Features of ACF Copilot Every Developer Should Know to be helpful as well.

<?php 
$site_title = get_field('site_title', 'option');
if ( $site_title ) {
    echo '<h1>' . esc_html($site_title) . '</h1>';
}
?>

This pulls data from the options page, ensuring dynamic content updates.

Enhancing the Custom Settings Page

Adding Conditional Logic

With ACF, conditional logic can hide or show fields based on user selections:

  1. In the field settings, enable Conditional Logic.
  2. Set rules, such as showing a field when a checkbox is checked.

Custom Styles and Scripts

To improve usability, enqueue styles and scripts:

add_action('admin_enqueue_scripts', function() {
    wp_enqueue_style('custom-admin-style', get_template_directory_uri() . '/admin-style.css');
    wp_enqueue_script('custom-admin-script', get_template_directory_uri() . '/admin-script.js', array('jquery'), null, true);
});

ACF Hooks for Advanced Logic

Extend functionality with hooks like acf/save_post:

add_action('acf/save_post', function( $post_id ) {
    if( $post_id == 'options' ) {
        // Custom logic for options page saves
    }
});

Best Practices for ACF Custom Settings Pages

  • Keep the layout simple and user-friendly.
  • Avoid overloading the page with unnecessary fields.
  • Document field names and their purposes for easier maintenance.

Conclusion

Using Custom Settings Page ACF, you can create powerful and user-friendly admin settings in WordPress. ACF’s flexibility makes it the go-to solution for developers seeking to streamline workflows while maintaining high-quality results. Explore the ACF documentation to dive deeper into its capabilities and start building custom settings pages that enhance your projects.

To enhance your understanding of Getting Started, take a look at our detailed guide on ACF Guide: What is Advanced Custom Fields? A Beginner's Guide