• Hi,

    Is it possible to target the plugin or GTM to delay or Defer it? Has it’s seriously hindered our performance (expected with GTM).

    I tried this but it was not successful:

    // Define a function to modify the GTM container code and add delay
    function custom_modify_gtm_tag( $gtm_tag ) {
        // Check if the input contains the noscript tag, which indicates the <noscript> part of the container code
        if ( strpos( $gtm_tag, '<noscript>' ) !== false ) {
            // If the noscript tag is present, return the original GTM container code as it's not suitable for delay
            return $gtm_tag;
        } else {
            // If the noscript tag is not present, modify the GTM container code to include delay
            $gtm_tag = '<script>
                            setTimeout(function() {
                                ' . $gtm_tag . '
                            }, 2000); // Delay in milliseconds
                        </script>';
    
            // Return the modified GTM container code
            return $gtm_tag;
        }
    }
    
    // Hook the function to the gtm4wp_get_the_gtm_tag filter
    add_filter( 'gtm4wp_get_the_gtm_tag', 'custom_modify_gtm_tag' );

    Thanks!

    Adam

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Delay or Defer’ is closed to new replies.