• Resolved Idel

    (@freetanga)


    Hi there! I’m usign this code…

    add_action( 'wp_head', function () { ?>
    <script>
    jQuery(document).ready(function() {
    	// xxxxxx
    });
    </script>
    <?php } );
    
    add_action( 'wp_enqueue_script', function () {
    	wp_enqueue_script( 'jquery' );
    } );

    posted here…

    https://www.ads-software.com/support/topic/add-jquery-possible/

    but I get this console error:

    Uncaught ReferenceError: jQuery is not defined

    How can I solve it? I just want to use a very simple jQuery function.

    Thank you! ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    If you want to wait to exclude your script after the page is ready, you can always just print it in the footer:

    add_action( 'wp_footer', function () { ?>
    <script>
    jQuery(document).ready(function() {
    	// xxxxxx
    });
    </script>
    <?php }, 15 );
    Thread Starter Idel

    (@freetanga)

    Same error ??

    Uncaught ReferenceError: jQuery is not defined

    Any idea why this can be happening?

    The website uses Elementor as Page Builder and all plugins, theme and WP are up to date.

    Here is a screenshot of the snippet applied:

    View post on imgur.com

    Thanks again ??

    Plugin Author Shea Bunge

    (@bungeshea)

    You still need to include the code to enqueue jQuery:

    add_action( 'wp_enqueue_scripts', function () {
    	wp_enqueue_script( 'jquery' );
    } );

    In fact, it looks like this might have been the problem with your original snippet: the hook is called wp_enqueue_scripts, not wp_enqueue_script.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Uncaught ReferenceError: jQuery is not defined’ is closed to new replies.