Reputation: 546
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)
Upvotes: 0
Views: 299
Reputation: 341
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
}
Upvotes: 1