dongzhang6677 2015-02-26 18:52
浏览 36
已采纳

Wordpress定制器打破了自定义控件

I'm hoping someone will help me find an answer to this. I am building a base child theme for the Genesis theme, & am adding to the Theme Customizer to allow quick setup of basic theme settings. Where I'm running into problems is that whenever I try to add a custom control the Customizer breaks. The site still works, just the customizer breaks. My code is this:

add_action( 'customize_register', 'um_register_theme_customizer' );
function um_register_theme_customizer( $wp_customize ) {

// Customizations that work here

I have setup basic color settings that all work. It breaks when I add this setting:

$wp_customize->add_setting(
    'um_h6_font_size',
    array(
        'default'     => '1.2'
    )
);
$wp_customize->add_control(
        new UM_Customize_Number_Control(
        'um_h6_font_size',
        array(
            'label'      => __( 'H6 Font Size (in rem)', 'um' ),
            'section'    => 'um_font_size_options',
            'settings'   => 'um_h6_font_size',
            'type' => 'number'
        )
        )
);

// Classes 
class UM_Customize_Number_Control extends WP_Customize_Control
{
    public $type = 'number';

    public function render_content()
    {
        ?>
        <label>
            <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
            <input type="number" size="2" step="1" min="0" value="<?php echo esc_attr(  $this->value() ); ?>" />
        </label>
        <?php
    }
}
} // Closes the um_register_theme_customizer function

If I remove the custom control then it works, defaulting to a text input (changing the type to text). What I'm trying to do is to make this a number field.

I was trying to use the same method to make a simple section of h6 text in the customizer for sub-headings, but was running into the same issue.

Any help as to why this isn't working would be greatly appreciated. I'm sure I'm missing something simple.

  • 写回答

1条回答 默认 最新

  • dongweicha6077 2015-12-09 18:34
    关注

    The answer to this was simple. You cannot set up a custom control inside of the main customizer function. It has to be added outside of that function. i.e. I now have a separate php file for custom controls that is included in my main functions file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料