Yogesh Chauhan's Blog

WordPress: How to setup and get values from an ACF options page?

in WordPress on May 18, 2021

Options page is only available via ACF PRO (ACF v5), or the options page add-on (ACF v4)

Options Page

When you want to add some fields that are globally accessible, meaning they are not limited to a page template, then this Options page becomes very handy. You can have tons of different fields to make your header and footer unique and beautiful.

Data saved in options fields is saved into wp_options table, making it accessible globally.

How to create an Options Page?

This is just a basic Options page creation code without passing any parameters.

Add this code to your functions.php file to to create an Options page.


if( function_exists('acf_add_options_page') ) {

Once you add that code and save your functions.php file, the default options page will show up on your wp-admin sidebar.

Create a customized options page

You can also create a bit advanced Options page with children.


if( function_exists('acf_add_options_page') ) {
		'page_title' 	=> 'Theme General Settings',
		'menu_title'	=> 'Theme Settings',
		'menu_slug' 	=> 'theme-general-settings',
		'capability'	=> 'edit_posts',
		'redirect'		=> false
		'page_title' 	=> 'Theme Header Settings',
		'menu_title'	=> 'Header',
		'parent_slug'	=> 'theme-general-settings',
		'page_title' 	=> 'Theme Footer Settings',
		'menu_title'	=> 'Footer',
		'parent_slug'	=> 'theme-general-settings',

Get values from an options page

You can use all WordPress template functions like get_field or the_field with Options page to get the values from a specific field, but with a second parameter. Which is just like passing a $post_id parameter to get metadata from a specific post object.

The second parameter required is a string with a word ‘option’ or ‘options’.

You can create multiple options page but the value retrieval is same for all of them. You still need to use the word ‘option’ or ‘options’ as the second parameter.

Give the gift of Audible

Display a field

Usually you’d get the value like this from any ACF field from a template page:

  <?php the_field('field_name'); ?>

So, all we need to do is to pass a second parameter to retrieve a value from an options page.

  <?php the_field('field_name', 'option'); ?>

Retrieve a field

$variable = get_field('field_name', 'option');
// do something with $variable

Display a sub field

To get a subfield, you don’t need to pass the second parameter inside the have_rows loop.

<?php if( have_rows('repeater', 'option') ): ?>


    <?php while( have_rows('repeater', 'option') ): the_row(); ?>

        <li><?php the_sub_field('title'); ?></li>

    <?php endwhile; ?>


<?php endif; ?>

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
Learn how to add Scroll Indicator using CSS and JavaScript?CSSperspective property in CSSCSSHow to create a Star Ratings using CSS?CSSCan Firewall and IDPS Stop DDoS Attack?MiscellaneousDoes :is() pseudo selector hint at CSS preprocessing in the future?CSSHow to create a smooth scrolling effect with CSS?CSS