How do I add a simple jQuery script to WordPress?

后端 未结 18 1844
心在旅途
心在旅途 2020-11-22 16:53

I read the Codex and a few blog posts about using jQuery in WordPress, and its very frustrating. I\'ve got as far as loading jQuery in functions.php file, but a

18条回答
  •  攒了一身酷
    2020-11-22 17:52

    You can add jQuery or javascript in theme's function.php file. The code is as below :

    add_action( 'wp_enqueue_scripts', 'add_my_script' );
    
    function add_my_script() {
    wp_enqueue_script(
        'your_script_name', // your script unique name 
        get_template_directory_uri().'/js/your-script.js', //script file location
        array('jquery') //lists the scripts upon which your script depends
    );
    }
    

    For more detail visit this tutorial : http://www.codecanal.com/add-simple-jquery-script-wordpress/

提交回复
热议问题