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.

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

报告相同问题?

悬赏问题

  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟