How can I remove jquery from the frontside of my WordPress?

前端 未结 10 920
逝去的感伤
逝去的感伤 2020-12-29 02:33

My wordpress site is a bit heavy to download. On the frontend, its including jquery unnecessarily. In my firebug it looks like:

jquery.js?ver=1.3.2
         


        
10条回答
  •  长情又很酷
    2020-12-29 03:01

    JQuery may be being added by your theme. If your theme is adding it properly, it should be using the wp_enqueue_script() function. To remove JQuery, simply use the wp_deregister_script() function.

    wp_deregister_script('jquery');
    

    Removing JQuery for your whole site might cause some unintended consequences for your admin section. To avoid removing JQuery on your admin pages, use this code instead:

    if ( !is_admin() ) wp_deregister_script('jquery');
    

    Now only pages that are not admin pages will run the wp_deregister_script() function.

    Add this code to the functions.php file in your theme directory.

提交回复
热议问题