Enqueue Wordpress Core jQuery at Footer

Discussion in 'Programming' started by HRA, Jun 12, 2015.

  1. #1
    Hi,

    Im trying to follow Google PageSpeed Insights suggestions and increase the PS Score.
    This is about render-blocking JavaScript in above-the-fold content
    Thing is I don't really know php or coding. I have a general idea and I read lot of tutorials and played with the code and I managed to fix above Google PS error.

    Problem is Im not sure how it will affect my site/ consequences.

    I edited the functions.php file of my theme. I pasted image + code Before and After I made the changes at end of the post if you want to take a look. Also list of plugins.

    These are my questions.

    01. As I copy pasted codes, I would like to know how those changes will affect my site? What could possibly go wrong? Where are the places I should check to see if something went wrong? Will there be any conflicts?

    02. Before I made changes, there were two files in the header (i.e. jquery.js AND jquery-migrate.min.js).
    After making changes I only see jquery.js in the footer.
    Should I worry about this?

    03. Lets assume something went wrong. Judging by the codes I modified, are they irreversible or undoing the changes will fix it?

    I wanted to ask these before I make these changes in the real site.

    Thanks.

    ____________________________

    BEFORE

    Google PSI: http://i61.tinypic.com/s77p.jpg

    CODE:
    function maya_classifieds_front_scripts() {
    wp_enqueue_script('jquery');
    
    wp_enqueue_script('maya-nuslider-js',JS.'/jquery.nouislider.min.js', array('jquery'),'1.0',true);
    wp_enqueue_script('maya-ad-genral-js',JS.'/maya-classified-genaral-script.js', array('jquery'),'1.0',true);
    wp_enqueue_script('maya-view-switcher-js',JS.'/maya-adspot-popup.js', array('jquery'),'1.0',true); //custom list/grid view switcher script and popup window script
     wp_localize_script( 'maya-view-switcher-js', 'classfiedAjaxParam', array('themeurl'=>THEMEROOT,));
     wp_enqueue_script( 'jquery-form',array('jquery'),false,true );
     wp_localize_script( 'jquery-form', 'jformparam', array( 'ajaxurl'=>admin_url( 'admin-ajax.php' ),));
    wp_enqueue_script('maya-genaral-js',JS.'/theme1-genaral.js', array('jquery'),'1.0',false);
    PHP:
    ____________________________

    AFTER

    Google PSI: http://i57.tinypic.com/t0oxh2.jpg

    CODE:
    function maya_classifieds_front_scripts() {
      wp_deregister_script( 'jquery' );
      wp_register_script( 'jquery', includes_url( '/js/jquery/jquery.js' ), false, NULL, true );
      wp_enqueue_script( 'jquery' );
    wp_enqueue_script('maya-nuslider-js',JS.'/jquery.nouislider.min.js', array('jquery'),'1.0',true);
    wp_enqueue_script('maya-ad-genral-js',JS.'/maya-classified-genaral-script.js', array('jquery'),'1.0',true);
    wp_enqueue_script('maya-view-switcher-js',JS.'/maya-view-switcher-popup.js', array('jquery'),'1.0',true); //custom list/grid view switcher script and popup window script
    wp_localize_script( 'maya-view-switcher-js', 'classfiedAjaxParam', array('themeurl'=>THEMEROOT,));
    wp_enqueue_script( 'jquery-form',array('jquery'),false,true );
    wp_localize_script( 'jquery-form', 'jformparam', array( 'ajaxurl'=>admin_url( 'admin-ajax.php' ),));
    wp_enqueue_script('maya-genaral-js',JS.'/theme1-genaral.js', array('jquery'),'1.0',false);
    PHP:
    ____________________________

    Plugin list
    https://wordpress.org/plugins/admin-menu-editor/
    https://wordpress.org/plugins/alchemist-ajax-upload/
    https://wordpress.org/plugins/contact-form-7/
    https://wordpress.org/plugins/dx-delete-attached-media/
    https://wordpress.org/plugins/frontend-edit-profile/
    https://wordpress.org/plugins/google-sitemap-generator/
    https://wordpress.org/plugins/image-cleanup/
    https://wordpress.org/plugins/meta-box/
    https://wordpress.org/plugins/options-framework/
    https://wordpress.org/plugins/regenerate-thumbnails/
    https://wordpress.org/plugins/simple-image-watermark/
    https://wordpress.org/plugins/simple-share-buttons-adder/
    https://wordpress.org/plugins/tinymce-advanced/
    https://wordpress.org/plugins/user-role-editor/
    https://wordpress.org/plugins/wc-shortcodes/
    https://wordpress.org/plugins/wordpress-importer/
    https://wordpress.org/plugins/wp-pagenavi/
     
    HRA, Jun 12, 2015 IP