0

I'm trying to make some customizer for my theme, but i've got JS error "Uncaught ReferenceError: wp is not defined " LOL. I wrote all code based on Codex, maybe it is just WP 3.8 bug? Or what i'm doing wrong?

my code - PHP:

add_action( 'customize_preview_init', 'customizer_preview' );

function customizer_preview() {
        wp_register_script( 'wproto-customizer-preview', get_template_directory_uri() . '/js/admin/screen-customizer.js', '', true );
        wp_enqueue_script( 'wproto-customizer-preview', array( 'jquery', 'customize-preview' ) );
}

JS:

( function( $ ) {

    // here i've got an error "wp is not defined"
    wp.customize( 'blogname', function( value ) {
        value.bind( function( newval ) {
            $( '#text-logo .site-title' ).html( newval );
        } );
    } );
} )( jQuery );

please help :)

1

I think your way of enqueueing is wrong here. When you use wp_register_script, you only need to pass the handle to wp_enqueue_script.

Try updating your function to:

function customizer_preview() {
  wp_enqueue_script( 'wproto-customizer-preview', get_template_directory_uri() . '/js/admin/screen-customizer.js', array( 'jquery', 'customize-preview' ) );
}
  • Who would have thought that the error at this! Thank you RRikesh, you are the Master :) – Dimon Dec 18 '13 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.