我正在为我的客户开发一个主题设置页面。我想添加一个主题选项页面来应用设置但我得到Wordpress错误“你没有足够的权限来访问这个页面。我认为我使用正确的代码,但问题仍然存在。 请帮我弄清楚我错在哪里
/*
* ADD THEME SETTINGS PAGE
*/
function vc_add_theme_settings_page(){
add_theme_page('Theme Settings','Theme Settings', 'manage_options' , 'vc_theme_page', 'vc_theme_page_display' );
}
add_action('admin_init', 'vc_add_theme_settings_page');
/*
* DISPLAY THEME SETTINGS PAGE
*/
function vc_theme_page_display(){
?>
<div class="wrap">
<h2>Vc Theme Settings Page</h2>
<form action="options.php" method="POST">
<?php settings_fields('vc_section'); ?>
<?php do_settings_sections('vc_theme_page'); ?>
<?php submit_button(); ?>
</form>
</div>
<?php
}
答案 0 :(得分:1)
以这种方式订购您的代码:
add_action('admin_menu', 'vc_add_theme_settings_pages');
add_action('admin_head', 'theme_styles');
add_action('admin_init', 'vc_add_theme_settings_page');
function vc_add_theme_settings_page(){
add_theme_page('Theme Settings','Theme Settings', 'edit_theme_options', 'manage_options', 'vc_theme_page_display' );
}
并尝试更改
<?php do_settings_sections('vc_theme_page'); ?>
的
<?php do_settings_sections(__FILE__); ?>
答案 1 :(得分:0)
add_action('admin_init', 'vc_add_theme_settings_page'); //instead of this
add_action('admin_menu', 'vc_add_theme_settings_page'); //try this
希望它对你有用。