How do I defer or async this WordPress javascript snippet to load lastly for faster page load times?

后端 未结 10 490
温柔的废话
温柔的废话 2020-12-07 09:28

I have various javascripts that are necessary plugins in one of my WordPress domains, and I know where in the php file it\'s called from.

I\'m taking every measure I

10条回答
  •  感情败类
    2020-12-07 09:32

    Another solution using a different filter, which can be used to target a specific script handle:

    function frontend_scripts()
    {
        wp_enqueue_script( 'my-unique-script-handle', 'path/to/my/script.js' );
    }
    add_action( 'wp_enqueue_scripts', 'frontend_script' );
    
    function make_script_async( $tag, $handle, $src )
    {
        if ( 'my-unique-script-handle' != $handle ) {
            return $tag;
        }
    
        return str_replace( '

提交回复
热议问题