WordPress定制器。 jQuery在settingspanel而不是预览

时间:2019-04-17 08:02:56

标签: php jquery wordpress

我正在尝试使用WP Settings API和jQuery为WP定制程序创建一些动态字段。 通过单选按钮的值给出,我想显示一些字段并隐藏另一个字段。当选择另一个收音机时,我要切换这些字段。 遗憾的是,jQuery似乎只能在定制程序提供的预览中使用,而不能在具有设置的面板上使用。

我已使用customize_preview_init挂钩将jQuery排入了定制程序,并通过settingsapi添加了设置。

jQuery:

jQuery( document ).ready( function($) {

    /* add the value. */
    $( "body" ).on( 'change', 'input[type="radio"]', function() { 
        alert();
    });
});

入队:

    function load_custom_wp_admin_scripts_mytheme() {
        wp_enqueue_script( 'customizer-mytheme',  get_stylesheet_directory_uri(). '/js/customizer-mytheme.js', array());
    }
    add_action( 'customize_preview_init', 'load_custom_wp_admin_scripts_mytheme' );

设置:

                $wp_customize->add_setting( 'call2action-external-bool' );
                $wp_customize->add_control( 'call2action-external-bool', array(
                    'label'      => 'Link naar?',
                    'section'   => 'enable_ph_slider',
                    'type'   => 'radio', // text (default), checkbox, radio, select, dropdown-pages
                    'choices'  => array(
                        'internal-link'  => 'Pagina in de website',
                        'external-link' => 'Externe website',
                    ),
                ));

0 个答案:

没有答案