Files
mataba/shop/xshop-theme/inc/performance/loader.php
T

19 lines
565 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
defined('ABSPATH') || exit;
/**
* Performance helpers – conditional asset loading, defer hints.
*/
add_filter('script_loader_tag', 'xshop_defer_scripts', 10, 3);
function xshop_defer_scripts(string $tag, string $handle, string $src): string {
// Defer theme script (not admin, not customizer preview).
if ($handle === 'xshop' && !is_admin() && !is_customize_preview()) {
if (str_contains($tag, ' defer')) { return $tag; }
$tag = str_replace('<script ', '<script defer ', $tag);
}
return $tag;
}