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.
//functions.php
if( function_exists('acf_add_options_page') ) {
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.
//functions.php
if( function_exists('acf_add_options_page') ) {
acf_add_options_page(array(
'page_title' => 'Theme General Settings',
'menu_title' => 'Theme Settings',
'menu_slug' => 'theme-general-settings',
'capability' => 'edit_posts',
'redirect' => false
));
acf_add_options_sub_page(array(
'page_title' => 'Theme Header Settings',
'menu_title' => 'Header',
'parent_slug' => 'theme-general-settings',
));
acf_add_options_sub_page(array(
'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:
So, all we need to do is to pass a second parameter to retrieve a value from an options page.
Retrieve a field
Display a sub field
To get a subfield, you don’t need to pass the second parameter inside the have_rows loop.
ACF advanced custom functions options pages post type