Lat*_*lla 1 php wordpress options advanced-custom-fields
我想向选项页面添加一个自定义子菜单,以便我可以使用我添加的回调函数呈现页面。如果我创建 acf_add_options_sub_page 我必须使用 acf 字段来生成选项页面。
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',
));
}
Run Code Online (Sandbox Code Playgroud)
add_action( 'admin_menu', 'main_home' );
/**
* Adds a submenu page under a custom post type parent.
*/
function main_home() {
add_submenu_page(
'theme-general-settings',
__( 'Books Shortcode Reference', 'textdomain' ),
__( 'Shortcode Reference', 'textdomain' ),
'manage_options',
'books-shortcode-ref',
'books_ref_page_callback'
);
}
/**
* Display callback for the submenu page.
*/
function books_ref_page_callback() {
?>
<div class="wrap">
<h1><?php _e( 'Books Shortcode Reference', 'textdomain' ); ?></h1>
<p><?php _e( 'Helpful stuff here', 'textdomain' ); ?></p>
</div>
<?php
}
Run Code Online (Sandbox Code Playgroud)
结果它不起作用:网址变成:website.com/wp-admin/books-shortcode-ref
如果我将 books-shortcode-ref 更改为 theme-general-settings 它可以工作,但它变得与过去使用的 acf 插件相同..我必须使用 acf 字段添加选项
请帮忙
小智 5
这里我刚刚用来将自定义子选项页面添加到 ACF 选项页面的代码应用于您的示例。您必须使用相同的标识符(在 ACF 和正常方式中)两次声明您的选项页面。所以,这有点棘手,但它有效:
function add_acf_option_page() {
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' => 'manage_options',
'redirect' => false
));
acf_add_options_sub_page( array(
'page_title' => __( 'Books Shortcode Reference', 'textdomain' ),
'menu_title' => __( 'Shortcode Reference', 'textdomain' ),
'parent_slug' => 'theme-general-settings',
'capability' => 'manage_options',
'menu_slug' => 'books-ref-page',
) );
}
}
add_action('acf/init', 'add_acf_option_page' );
function add_custom_option_page() {
add_submenu_page(
null,
__( 'Books Shortcode Reference', 'textdomain' ),
__( 'Shortcode Reference', 'textdomain' ),
'manage_options',
'books-ref-page',
'books_ref_page_callback'
}
add_action('admin_menu', 'add_custom_option_page');
function books_ref_page_callback() {
?>
<div class="wrap">
<h1><?php _e( 'Books Shortcode Reference', 'textdomain' ); ?></h1>
<p><?php _e( 'Helpful stuff here', 'textdomain' ); ?></p>
</div>
<?php
}
Run Code Online (Sandbox Code Playgroud)
我希望它有帮助!
| 归档时间: |
|
| 查看次数: |
1307 次 |
| 最近记录: |