Skip to main content
added 61 characters in body
Source Link
Gabriel
  • 2.2k
  • 10
  • 22
  • 24

Here is the easy way for adding asynchronous to all custom js filefiles in wordpressWordPress.

Add in functions.php

// Async load for all style function base_async_scripts($url) { if ( strpos( $url, '#asyncload') === false ) return $url; else if ( is_admin() ) return str_replace( '#asyncload', '', $url ); else return str_replace( '#asyncload', '', $url )."' async='async"; } add_filter( 'clean_url', 'base_async_scripts', 11, 1functions.php );:

//add or change in url as mentioned below wp_enqueue_script( 'base-functions', get_template_directory_uri() . '/js/functions.js#asyncload', array( 'jquery' ), null, true );

// Async load for all style
    function base_async_scripts($url)
    {
        if ( strpos( $url, '#asyncload') === false )
            return $url;
        else if ( is_admin() )
            return str_replace( '#asyncload', '', $url );
        else
        return str_replace( '#asyncload', '', $url )."' async='async"; 
        }
    add_filter( 'clean_url', 'base_async_scripts', 11, 1 );

//add or change in url as mentioned below
wp_enqueue_script( 'base-functions', get_template_directory_uri() . '/js/functions.js#asyncload', array( 'jquery' ), null, true );

Here is the easy way for adding asynchronous to all custom js file in wordpress

Add in functions.php

// Async load for all style function base_async_scripts($url) { if ( strpos( $url, '#asyncload') === false ) return $url; else if ( is_admin() ) return str_replace( '#asyncload', '', $url ); else return str_replace( '#asyncload', '', $url )."' async='async"; } add_filter( 'clean_url', 'base_async_scripts', 11, 1 );

//add or change in url as mentioned below wp_enqueue_script( 'base-functions', get_template_directory_uri() . '/js/functions.js#asyncload', array( 'jquery' ), null, true );

Here is the easy way for adding asynchronous to all custom js files in WordPress.

Add in functions.php :

// Async load for all style
    function base_async_scripts($url)
    {
        if ( strpos( $url, '#asyncload') === false )
            return $url;
        else if ( is_admin() )
            return str_replace( '#asyncload', '', $url );
        else
        return str_replace( '#asyncload', '', $url )."' async='async"; 
        }
    add_filter( 'clean_url', 'base_async_scripts', 11, 1 );

//add or change in url as mentioned below
wp_enqueue_script( 'base-functions', get_template_directory_uri() . '/js/functions.js#asyncload', array( 'jquery' ), null, true );
Source Link
user86710
user86710

Here is the easy way for adding asynchronous to all custom js file in wordpress

Add in functions.php

// Async load for all style function base_async_scripts($url) { if ( strpos( $url, '#asyncload') === false ) return $url; else if ( is_admin() ) return str_replace( '#asyncload', '', $url ); else return str_replace( '#asyncload', '', $url )."' async='async"; } add_filter( 'clean_url', 'base_async_scripts', 11, 1 );

//add or change in url as mentioned below wp_enqueue_script( 'base-functions', get_template_directory_uri() . '/js/functions.js#asyncload', array( 'jquery' ), null, true );