简体   繁体   中英

trying to add a custom menu page to my wordpress theme

I'm trying to add a custom menu page (under appearance) to a custom wordpress theme, but something is going wrong with my hooks. the error i'm getting is:

*Warning: Cannot modify header information - headers already sent by (output started at /home3/keganqui/public_html/optimus/wp-content/themes/optimus/functions.php:2) in /home3/keganqui/public_html/optimus/wp-admin/theme-editor.php on line 103*

my theme options are appearing on every single page, site wide (not just the backend). for some reason, the tag is being stripped of all content and the body starts with

<body>
<div id="wrap">HTML FOR MY THEME OPTIONS</div>
<title>page title</title>
...all other info that should be in <head>

i'm not sure i'm doing a good job explaining this, so check out www.keganquimby.com/optimus (that ugly gray box is my theme options)

add_action('admin_init', 'theme_options_init');
add_action('admin_menu', 'theme_options_add_page');

function theme_options_init() {
    register_setting('theme_options', 'mytheme_theme_options', 'theme_options_validate');
}

function theme_options_add_page() {
    $page = add_theme_page(__('Theme Options', 'mytheme' ), __('Theme Options', 'mytheme'), 'edit_theme_options', 'theme_options', 'theme_options_do_page');
    add_action('admin_print_styles-'.$page, 'theme_options_js');
}

function theme_options_js() {
    // whatever js you need...
    wp_enqueue_script('jquery-ui-core');
}

function theme_options_validate($input) {
    $input['sometextarea'] = wp_filter_post_kses($input['sometextarea']);
    return $input;
}

function theme_options_do_page() {

    if (!isset($_REQUEST['settings-updated'])) {
        $_REQUEST['settings-updated'] = false;
    }

    ?><div>

    your theme options page 

    </div><?php

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM