How to fix the WordPress error ‘You do not have sufficient permissions to access this page’ that occurs when adding a theme options page?

Solution: 1

Reorder your code as follows:


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',          // Page title
        'Theme Settings',          // Menu title
        'edit_theme_options',      // Capability
        'manage_options',          // Menu slug
        'vc_theme_page_display'    // Callback function
    );
}

Then, in your settings page template, replace:


<?php do_settings_sections('vc_theme_page'); ?>

with:


<?php do_settings_sections(__FILE__); ?>

This ensures WordPress correctly registers and displays your theme settings sections.

Solution: 2

If your settings page isn’t working, try changing the hook for your function.

Replace this:


<?php add_action('admin_init', 'vc_add_theme_settings_page'); ?>

With this:


<?php add_action('admin_menu', 'vc_add_theme_settings_page'); ?>

This ensures that your theme settings page is added at the correct point in the WordPress admin menu loading process.