【问题标题】:trying to add a custom menu page to my wordpress theme尝试将自定义菜单页面添加到我的 wordpress 主题
【发布时间】:2012-02-01 02:07:36
【问题描述】:

我正在尝试将自定义菜单页面(在外观下)添加到自定义 wordpress 主题,但我的钩子出了点问题。我得到的错误是:

*警告:无法修改标头信息 - 标头已由 /home3/keganqui/public_html/ 中的(输出开始于 /home3/keganqui/public_html/optimus/wp-content/themes/optimus/functions.php:2)发送optimus/wp-admin/theme-editor.php 第 103 行*

我的主题选项出现在站点范围内的每个页面上(不仅仅是后端)。出于某种原因,标签的所有内容都被剥离了,正文以

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

我不确定我是否能很好地解释这一点,所以请查看www.keganquimby.com/optimus(那个丑陋的灰色框是我的主题选项)

【问题讨论】:

  • 在第 2 行检查 wp-content/themes/optimus/functions.php。浏览器有一些输出,不应该存在。

标签: php wordpress


【解决方案1】:
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

}

【讨论】:

  • 如何保存设置?出于某种原因,格式是正确的,但是当我更改设置时它没有保存。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-29
  • 1970-01-01
  • 1970-01-01
  • 2012-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多