19 lines
565 B
PHP
19 lines
565 B
PHP
<?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;
|
||
}
|