Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am having a rather difficult time adding a script to the 3.4 Theme Customizer (i.e., customize.php). If I want, I can deregister jquery and add it from googleapi as follows:

wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js');
wp_enqueue_script( 'jquery' );

That works just fine. However, if I want to add jquery-color or some other script I just can't get it to work. For instance, this doesn't work:

wp_enqueue_script( 'jquery-color' );

This also does not work:

wp_register_script( 'bpjquerycolor', 'http://localhost/bp2/wp-content/themes/buildpress/admin/scripts/bpjquerycolor.js');

wp_enqueue_script( 'bpjquerycolor' );

In terms of add_action, none of the following work:

add_action( 'admin_print_scripts', 'add_admin_scripts' );
add_action( 'wp_enqueue_scripts', 'add_admin_scripts' );
add_action( 'init', 'add_admin_scripts' );
add_action( 'admin_init', 'add_admin_scripts' );

I have also tried the following with no success:

global $wp_customize;
if ( isset( $wp_customize ) ) {
wp_enqueue_script( 'jquery-color' );
}

In short, I've tried every combination that I can think of with no success.

What am I doing wrong? How can I add this to the theme customizer?

Thanks in advance for any help you can offer.

share|improve this question
add comment

2 Answers

Okay, I figured it out. Instead of "init" or "wp_enqueue_scripts", etc. I had to use "customize_controls_print_footer_scripts" as such:

add_action( 'customize_controls_print_footer_scripts', 'bp_admin_scripts' );

If you want the script in the header then you use: "customize_controls_print_scripts"

And if you want to enqueue a style you use "customize_controls_print_styles"

I found this out by looking at the code for customize.php and noting the add_action codes used there on lines 30 - 32 (as of version 3.4.1)

share|improve this answer
add comment

It appears that 'customize_controls_enqueue_scripts' also works and may be the intended function.

function theme_customize_style() {
    wp_enqueue_style('customize-styles', get_template_directory_uri() . '/customize.css');
}
add_action( 'customize_controls_enqueue_scripts', 'theme_customize_style' );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.