Note that there are some explanatory texts on larger screens.

plurals
  1. POWordpress use script only if class exist (or method)
    text
    copied!<p>i have a problem with script in wordpress. I have included script in functions.php in theme folder</p> <pre><code>function my_scripts_method() { wp_register_script( 'my-js-file', get_template_directory_uri() . '/js/my-js.js', array( 'jquery' ), '1.0', false ); wp_enqueue_script( 'my-js-file' ); } add_action( 'wp_enqueue_scripts', 'my_scripts_method' ); </code></pre> <p>and my script with some adjustments in my datepicker ui. But that script is included all the time and when the form with datepicker in not on the page, it doesn't knows "datepicker" and its methods. Web is than without the background and with other problems. </p> <p>I figured out, that i can check, if the class of forms date field exists or the whole plugin (its visual form builder) is on that page, but it doesn't work. Wordpress is processing that script even if the class is not on current page.</p> <p>i tried many things like</p> <pre><code>if ($(".visual-form-builder-container")){ </code></pre> <p>but it still loads that script on the main page, where this element doesn't exists. Please help</p> <p>this is that script:</p> <pre><code>if($(".visual-form-builder-container").length &gt; 0) { &lt;-- Im trying to stop that here jQuery(document).ready(function($) { $.datepicker.setDefaults({ firstDay: 1, minDate: 0, }); }); } </code></pre> <p>EDIT: Maybe i found something. When i open my website without any "if" in my scrip and check the chrome console, there is: Uncaught TypeError: Cannot call method 'setDefaults' of undefined So if i maybe need something like: if is method defined and than it should work but i do not know any function, that checks methods....</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload