Wordpress定制器输出值

时间:2017-07-12 05:21:52

标签: javascript php jquery wordpress

使用Sage Roots主题我无法从自定义程序设置输出值。设置/选项显示在管理员上,然后我填写但不会输出。

Customizer.php

function customize_register($wp_customize) {

$wp_customize->add_setting(
'my_label',
array(
  'default' => '',
  'sanitize_callback' => 'sanitize_text_field'
)
);
$wp_customize->add_control(
  'my_label',
  array(
    'label' => 'My Label',
    'section' => 'title_tagline',
    'settings' => 'my_label',
    'transport' => 'postMessage'
  )
);

}
add_action('customize_register', __NAMESPACE__ . '\\customize_register');

Customizer.js

(function($) {
  wp.customize('my_label', function(value) {
    value.bind(function(to) {
      $('.my-label').text(to);
    });
  });
})(jQuery);

HTML

<a href="http://www.example.com" title="My label"><button class="btn btn-primary pull-left my-label" alt="my label" ></button></a>

1 个答案:

答案 0 :(得分:1)

没关系我找到答案..

<a href="http://www.example.com" title="My label"><button class="btn btn-primary pull-left my-label" alt="my label" ><?php echo get_theme_mod(  'my_label', '' ); ?></button></a>