Forums

Using jQuery (5 posts)

  1. whajrog
    Member
    Posted 5 months ago #

    Hi. I am trying to figure out how to use jQuery in WordPress. is there a special syntax I have to use? I;ve tried countless times and now, I see I need help. Any help would greatly be appreciated.

  2. David Gwyer
    Member
    Posted 5 months ago #

    Use the jQuery built-in to WordPress and ALWAYS use the wp_enqueue_script() function to add your scripts correctly.

    http://codex.wordpress.org/Function_Reference/wp_enqueue_script

    So, to use jQuery on the front end of your site use something like:

    function add_jquery() {
        wp_enqueue_script( 'jquery' );
    }
    add_action('wp_enqueue_scripts', 'add_jquery');
  3. whajrog
    Member
    Posted 5 months ago #

    Thank you, David.

  4. whajrog
    Member
    Posted 5 months ago #

    Oh also, do I add this in the head?

  5. David Gwyer
    Member
    Posted 5 months ago #

    No.

    It get's added to the header via the add_action('wp_enqueue_scripts', 'add_jquery'); hook.

    Just add the code anywhere inside your themes functions.php file.

Reply

You must log in to post.

About this Topic