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.

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 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
Give buttons accessible namesUI/UXHow to avoid element shift on border change while hovering in CSS?CSSJavaScript Data Types and Data Structures Things to RememberJavaScriptHow to import a CSS file using PHP code and not HTML code?PHPHow to overwrite file contents with new content in PHP?PHPKilling A Project Part 2: Who should make the decision to kill a project?Miscellaneous