add_filter('script_loader_tag', function($tag, $handle) {
    $defer = ['owl-carousel', 'swiper'];
    foreach ($defer as $h) {
        if (str_contains($handle, $h)) {
            return str_replace(' src=', ' defer src=', $tag);
        }
    }
    return $tag;
}, 10, 2);

add_filter('wp_get_attachment_image_attributes', function($attr, $attachment, $size) {
    static $first = true;
    if ($first && isset($attr['class']) && str_contains($attr['class'], 'wp-image-7805')) {
        $attr['fetchpriority'] = 'high';
        $attr['loading'] = 'eager';
        $first = false;
    }
    return $attr;
}, 10, 3);

add_action('wp_head', function() {
    echo '<link rel="preconnect" href="https://jaynes-bridal-pull-zone.b-cdn.net/" crossorigin>';
    echo '<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>';
    echo '<link rel="preconnect" href="https://fonts.googleapis.com">';
}, 1);

add_action('wp_footer', function() {
    ?>
    <script>
    document.querySelectorAll('.elementor-background-video-hosted').forEach(function(v) {
        v.preload = 'none';
        v.setAttribute('preload', 'none');
    });
    </script>
    <?php
}, 5);