

/****************************************************************************************
 * PERFORMANCE OPTIMIZATIONS FOR SEO HIRED GUN SITES
 * Defer JS, optimize CSS delivery, add image dimensions
 ****************************************************************************************/

/**
 * Defer non-critical JavaScript
 * Adds defer attribute to scripts that don't need to block rendering
 */
function seogunslinger_defer_scripts($tag, $handle) {
    // Scripts to defer - adjust based on what's actually enqueued on your site
    $defer_scripts = array(
        'jquery',
        'jquery-migrate',
        'wp-block-library',
        'wp-block-library-theme',
        'woocommerce-blocktheme-css', // Handle might differ
        'contact-form-7',
        // Add WooCommerce scripts if needed
        'wc-add-to-cart',
        'wc-cart-fragments',
        'wc-single-product',
        'wc-add-to-cart-variation',
        'wc-cart',
        'wc-checkout',
        'wc-shipping',
    );

    foreach ($defer_scripts as $defer_script) {
        if ($defer_script === $handle) {
            return '<script src="' . esc_url( $src ) . '" defer="defer"' . $type . '></script>';
        }
    }
    return $tag;
}
add_filter('script_loader_tag', 'seogunslinger_defer_scripts', 10, 2);

/**
 * Defer non-critical CSS by preloading
 * Changes stylesheet tags to preload then switch to stylesheet onload
 */
function seogunslinger_defer_styles($tag, $handle, $href, $media) {
    // Don't defer critical above-the-fold CSS (we'll inline it instead)
    // For now, defer all stylesheets - you can exclude specific handles if needed
    return '<link rel="preload" href="' . esc_url( $href ) . '" as="style" onload="this.rel='stylesheet'"' . ($media ? ' media="' . esc_attr( $media ) . '"' : '') . '>';
}
add_filter('style_loader_tag', 'seogunslinger_defer_styles', 10, 4);

/**
 * Add missing width/height attributes to images to prevent layout shift
 */
function seogunslinger_add_img_attr($attr, $attachment, $size) {
    // Remove title attribute for accessibility and SEO
    if (isset($attr['title'])) {
        unset($attr['title']);
    }
    
    // Add missing dimensions
    if (!isset($attr['width']) && !isset($attr['height'])) {
        $image_info = wp_get_image_attachment_metadata($attachment['ID']);
        if (!empty($image_info['width']) && !empty($image_info['height'])) {
            $attr['width'] = $image_info['width'];
            $attr['height'] = $image_info['height'];
        }
    }
    return $attr;
}
add_filter('wp_get_attachment_image_attributes', 'seogunslinger_add_img_attr', 10, 3);

/**
 * Optional: Remove unused WooCommerce styles/scripts if not needed on all pages
 */
// Uncomment if you want to disable WooCommerce styles on non-WooCommerce pages
// function seogunslinger_manage_woocommerce_styles() {
//     if ( function_exists( 'is_woocommerce' ) ) {
//         if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
//             wp_dequeue_style( 'woocommerce-layout-css' );
//             wp_dequeue_style( 'woocommerce-smallscreen-css' );
//             wp_dequeue_style( 'woocommerce-general-css' );
//             wp_dequeue_style( 'woocommerce-blocktheme-css' );
//             wp_dequeue_script( 'wc-add-to-cart' );
//             wp_dequeue_script( 'wc-cart-fragments' );
//             wp_dequeue_script( 'wc-single-product' );
//             wp_dequeue_script( 'wc-add-to-cart-variation' );
//             wp_dequeue_script( 'wc-cart' );
//             wp_dequeue_script( 'wc-checkout' );
//             wp_dequeue_script( 'wc-shipping' );
//             wp_dequeue_script( 'wc-add-to-cart-variation' );
//         }
//     }
// }
// add_action( 'wp_enqueue_scripts', 'seogunslinger_manage_woocommerce_styles', 99 );
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//blog.seogunslinger.com/wp-content/plugins/wordpress-seo/css/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://blog.seogunslinger.com/post-sitemap.xml</loc>
		<lastmod>2026-04-26T19:41:29+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://blog.seogunslinger.com/page-sitemap.xml</loc>
		<lastmod>2026-04-26T19:41:27+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://blog.seogunslinger.com/category-sitemap.xml</loc>
		<lastmod>2026-04-26T19:41:29+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://blog.seogunslinger.com/author-sitemap.xml</loc>
		<lastmod>2026-04-27T00:10:33+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Yoast SEO -->