Create a WordPress option page with ACF

When you are developing a theme or plugin, you might need to have an option page for your theme or plugin settings. Its is very easy to have that page with the help of ACF ( Advance Custom Field ) plugin. You also need to have pro version of this plugin to working properly.

Let’s dive into the code.

First you need to check whether the acf_add_options_page() function exists or not. If it is, then you need to put your information inside that function.

if ( function_exists( 'acf_add_options_page' ) ) {}

Now you need to pass an array with your information like page title, menu title, slug, compatibility like below. 

acf_add_options_page(
array(
	'page_title' => 'Theme Option Panel',
	'menu_title' => 'Theme Settings',
	'menu_slug'  => 'theme-settings',
	'capability' => 'edit_posts',
	'redirect'   => false,
)
);

Its will gives you an option page like below.

Now you can add your custom fields for the global settings of your theme or plugin.

You can find more information on it from this link.

Published
Categorized as Dev

Leave a comment

Your email address will not be published.