WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i am tring to load some jquery code to make validation in the theme customizer. i have created 10 checkboxes to show some info. but i want to limited the user to choose only 5 checkboxes. so i have created jquery code to do so, and this code works fine when i put this code in the chrome console.

$("#section id input[type=checkbox]").click(function(){
    var countchecked = $("#section id input[type=checkbox]:checked").length;

    if(countchecked >= 2) 
        $('#section id input[type=checkbox]').not(':checked').attr("disabled",true);
        $('#section id input[type=checkbox]').not(':checked').attr("disabled",false);

what i have missed? which codec i need to use to insert in functions.php that will load some jquery code when the user using customize.php (theme customizer)?

i want to make all the validation before user trying to save all the changes.

thanks for help.

share|improve this question

Create a /js subfolder in your theme directory, if such does not exist already.
Save your script to a file in said folder.

Then, in functions.php:

if ( is_admin() ) {
    global $pagenow;

    if ( 'customize.php' === $pagenow ) {
        add_action( 'admin_enqueue_scripts', 'wpse107236_enqueue_customizer_script' );

function wpse107236_enqueue_customizer_script() {
        get_template_directory_uri . '/js/your-script.js',
        array( 'jquery' ),

Related Resources:

share|improve this answer
Hello Johannes Pille, it seems not working. i try in this way and the "if" here is not working if i write this outside from the "if" "add_action( 'wp_enqueue_scripts', 'wpse107236_enqueue_customizer_script' );" i get "Hello World" i created js fille and put there jQuery(document).ready(function ($) { alert("Hello World"); }); in the same file i have my code i have paste above but it not working. – someone Jul 20 '13 at 10:29
maybe you have some other solution for this? it can be done by php validation if there is a problem to run custom jquery for customizer. thanks – someone Jul 21 '13 at 4:07

Your Answer


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

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