This is my first page of the plugin    

        Plugin Name: guard_search plugin
        Description: Search Plugon
        Author: mazhar

wp_enqueue_script( 'my-ajax-handle', plugin_dir_url( _FILE_ ) . 'guards_search/js/ajax.js', array( 'jquery' ) );
        wp_localize_script( 'my-ajax-handle', 'the_ajax_script', array( 'ajaxurl' => admin_url('admin-ajax.php' )));

       wp_register_style('jquery.formstyler', plugin_dir_url( _FILE_ ) . 'guards_search/css/jquery.formstyler.css');

        wp_register_style('jquery.formstyler', plugin_dir_url( _FILE_ ) . 'guards_search/js/jquery.formstyler.min.js');

        wp_register_script('prefix_bootstrap', plugin_dir_url( _FILE_ ) . 'guards_search/js/bootstrap.min.js');

        wp_register_style('prefix_bootstrap', plugin_dir_url( _FILE_ ) . 'guards_search/css/bootstrap.min.css');

        add_action( 'wp_ajax_models_click', 'models_click');
        add_action( 'wp_ajax_nopriv_models_click', 'models_click');

        add_action( 'wp_ajax_reset_years', 'reset_years');
        add_action( 'wp_ajax_nopriv_reset_years', 'reset_years');

This is my ajax.js where the problems lies where styler is undefined(problem) which is the part of jquery's formstyller plugin mentioned in my first page.

 jQuery(document).ready(function() {
   jQuery('input, select').styler({
                selectSearch: true,

1) My first question is how will i use jquery in my first page.

2) My second question is if i may how can i transport jquery.formstyller plugin in my ajax.js.


You will have to load jquery.formstyler first to use it in your ajax.js. You can add it as another dependancie like jquery itself.

wp_enqueue_script( 'my-ajax-handle', plugin_dir_url( _FILE_ ) . 'guards_search/js/ajax.js', array( 'jquery', 'jquery.formstyler' ) );

Also you have a little syntax issue in:

wp_register_style('jquery.formstyler', plugin_dir_url( _FILE_ ) . 'guards_search/js/jquery.formstyler.min.js');

It should be register script, not style. same with the line below wp_enqueue_style('jquery.formstyler');. add as wp_enqueue_script('jquery.formstyler'); script instead as style!

|improve this answer|||||
  • i have two files formstyler.css and formstyler.js. i should have two enqueue with different name? or same name – maztt Oct 30 '18 at 9:17
  • you can add them with the same name. but not both as a style. see wp_register_style is wrong for your script – André Kelling Oct 30 '18 at 9:28
  • so the bottom line is formstyler.css and formstyler.js would be added as wp_enqueue_style and wp_enqueue_script but with the same name – maztt Oct 30 '18 at 9:42
  • and wp_enqueue_script( 'my-ajax-handle', plugin_dir_url( FILE ) . 'guards_search/js/ajax.js', array( 'jquery', 'jquery.formstyler' ) ); will be added next in the hierachy? – maztt Oct 30 '18 at 9:43
  • it has started giving me jquery.formstyler.min.js?ver=4.9.8:2 Uncaught ReferenceError: jQuery is not defined error now – maztt Oct 30 '18 at 9:50

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.