Last active
March 4, 2022 21:49
-
-
Save taotiwordpress/1328d7e73c8fafbdbd67fe5bb476eb05 to your computer and use it in GitHub Desktop.
[Add options page functionality (and for custom post types )] #php #acf #acf-options #options-page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( function_exists( 'acf_add_options_page' ) ) { | |
/** | |
* Example: Single 'Theme Settings' page, with children | |
* | |
* These only create the pages, which must be then populated via custom ACF fields. | |
* This setup creates a 'parent' ACF config page and sub-pages. | |
*/ | |
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( // Could easily be 'Header', 'Hero', or 'Slider'. | |
array( | |
'page_title' => 'Theme Footer Settings', | |
'menu_title' => 'Footer', | |
'parent_slug' => 'theme-general-settings', | |
) | |
); | |
acf_add_options_sub_page( | |
array( | |
'page_title' => 'Analytics Tracking Code', | |
'menu_title' => 'Analytics Tracking Code', | |
'parent_slug' => 'theme-general-settings', | |
) | |
); | |
/** | |
* Example: Options page for single Custom Post-Type | |
*/ | |
acf_add_options_page( | |
array( | |
'page_title' => 'Training Hero Content', | |
'menu_title' => 'Training Hero Content', | |
'menu_slug' => 'options_training', | |
'capability' => 'edit_posts', | |
'parent_slug' => 'edit.php?post_type=training', | |
'position' => false, | |
'icon_url' => 'dashicons-images-alt2', | |
'redirect' => false, | |
), | |
); | |
/** | |
* Example: Default '404' options page | |
* | |
* @note: This could also be accomplished as a theme setting. | |
*/ | |
acf_add_options_page( | |
array( | |
'page_title' => '404 Page Options', | |
'parent_slug' => 'themes.php', | |
) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment