enqueued ) { return; } wp_register_script( 'adxbyms-gpt', 'https://securepubads.g.doubleclick.net/tag/js/gpt.js', array(), '1.0.0', false // Load in head for earlier slot registration or footer if preferred. We set to false (head) but async so it doesn't block rendering. ); wp_enqueue_script( 'adxbyms-gpt' ); $this->enqueued = true; } /** * Force async attribute on GPT script tag. * * @param string $tag The script tag. * @param string $handle The script handle. * @return string The modified script tag. */ public function force_async_attribute( $tag, $handle ) { if ( 'adxbyms-gpt' === $handle && false === strpos( $tag, ' async' ) ) { $tag = str_replace( ' src', ' async src', $tag ); } return $tag; } /** * Print global init script to prevent duplicate googletag definitions. */ public function print_inline_gpt_init() { // Define window.googletag once globally ?> format_sizes_for_js( $sizes ); // Hostname dynamic setting $site_host = wp_parse_url( get_site_url(), PHP_URL_HOST ); // Build slot JS call ob_start(); ?>