Deferring JS / Theme look , appearance - by Schubfaktor

This topic has 2 replies, 2 voices, and was last updated 7 years, 5 months ago ago by Olga Barlow

  • Avatar: Schubfaktor
    Schubfaktor
    Participant
    June 24, 2017 at 11:24

    Hey….i would like to defer js files and i have tried to use following code in my function.php

    function defer_parsing_of_js ( $url ) {
    if ( FALSE === strpos( $url, ‘.js’ ) ) return $url;
    if ( strpos( $url, ‘jquery.js’ ) ) return $url;
    return “$url’ defer “;
    }
    add_filter( ‘clean_url’, ‘defer_parsing_of_js’, 11, 1 );

    But with this code all xstore shortcodes are broken in their appearance…..

    Is there any hint to solve that problem?? Maybe any code to exclude the js files of the theme?

    Thanks a lot

    1 Answer
    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    June 27, 2017 at 13:30

    Hello,

    Try the following code instead of that one

    function defer_parsing_of_js ( $url ) {
    
    	if ( ( FALSE === strpos( $url, ‘.js’ ) )  || ( strpos( $url, ‘jquery.js’ ) > 0 ) || ( strpos( $url, ‘head.min.js’ ) > 0 ) ) return $url;
    
    	return “$url’ defer “;
    }

    Also, there is special WP plugin for these purposes WP deferred javaScript.

    Regards

  • Viewing 2 results - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.Log in/Sign up

8theme customization service
We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.