Reply 190136 to: Eliminate render-blocking JavaScript and CSS in above-the-fold content

Avatar: Olga Barlow
Olga Barlow
Support staff
April 3, 2018 at 14:54

Hello,

1) Autoptimize. Exclude head.js file http://prntscr.com/j0933y
2), 3) To remove font, add Roboto only and move styles and scripts to footer add the following code in child theme functions.php

function etheme_enqueue_styles() {
   global $etheme_responsive, $etheme_theme_data;
    $etheme_theme_data = wp_get_theme( 'legenda' );

    if ( !is_admin() ) {

        $script_depends = array();

        if(class_exists('WooCommerce')) {
            $script_depends = array('wc-add-to-cart-variation');
        }

        wp_enqueue_script('head', get_template_directory_uri().'/js/head.js'); // modernizr, owl carousel, Swiper, FullWidth helper
        if(etheme_get_option('product_img_hover') == 'tooltip'){
            wp_enqueue_script('tooltip', get_template_directory_uri().'/js/tooltip.js');
        }
        wp_enqueue_script('jquery');
        wp_enqueue_script('all_plugins', get_template_directory_uri().'/js/plugins.min.js',$script_depends,false,true);
        wp_enqueue_script('waypoints');

        wp_enqueue_script('etheme', get_template_directory_uri().'/js/etheme.js',$script_depends,false,true);

        wp_localize_script( 'etheme', 'myAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'noresults' => __('No results were found!', 'legenda')));
        wp_localize_script( 'all_plugins', 'ethemeLocal', array('tClose' => __('Close (Esc)', 'legenda')));

    }
}

function add_footer_styles() {
    global $etheme_responsive, $etheme_theme_data;
    $etheme_theme_data = wp_get_theme( 'legenda' );

    $custom_css = etheme_get_option('custom_css');

    if ( !is_admin() ) {

        wp_enqueue_style("et-font-awesome",get_stylesheet_directory_uri().'/css/font-awesome.css', array( 'fonts' ) );
        wp_enqueue_style("style",get_stylesheet_directory_uri().'/style.css', array(), $etheme_theme_data->Version);

        wp_enqueue_style("font-roboto",et_http()."fonts.googleapis.com/css?family=Roboto:300,400,500,700");
        wp_enqueue_style('js_composer_front');

        if($etheme_responsive){
            wp_enqueue_style("responsive",get_template_directory_uri().'/css/responsive.css', array(), $etheme_theme_data->Version);
        }

        if($custom_css) {
            wp_enqueue_style("custom",get_template_directory_uri().'/custom.css', array(), $etheme_theme_data->Version);
        }

        $etheme_color_version = etheme_get_option('main_color_scheme');

        if($etheme_color_version=='dark') {
            wp_enqueue_style("dark",get_template_directory_uri().'/css/dark.css', array(), $etheme_theme_data->Version);
        }
    }
};
add_action( 'get_footer', 'add_footer_styles' );

Regards

Go To The Whole Conversation In Topic
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.