add_filter('wp_handle_upload', 'td_convert_webp_to_jpg_on_upload', 5);

function td_convert_webp_to_jpg_on_upload($upload) {
    if (!isset($upload['type']) || $upload['type'] !== 'image/webp') {
        return $upload;
    }

    $file_path = $upload['file'];
    $new_path  = preg_replace('/\.webp$/i', '.jpg', $file_path);
    $saved     = false;

    // Try GD first
    if (function_exists('imagecreatefromwebp')) {
        $image = @imagecreatefromwebp($file_path);
        if ($image) {
            $width  = imagesx($image);
            $height = imagesy($image);
            $bg = imagecreatetruecolor($width, $height);
            imagefill($bg, 0, 0, imagecolorallocate($bg, 255, 255, 255));
            imagecopy($bg, $image, 0, 0, 0, 0, $width, $height);
            $saved = imagejpeg($bg, $new_path, 90);
            imagedestroy($image);
            imagedestroy($bg);
        }
    }

    // Fallback to Imagick if GD failed or lacks webp support
    if (!$saved && class_exists('Imagick')) {
        try {
            $imagick = new Imagick($file_path);
            $imagick->setImageFormat('jpeg');
            $imagick->setImageCompressionQuality(90);
            $imagick->setImageBackgroundColor('white');
            $imagick = $imagick->flattenImages();
            $saved = $imagick->writeImage($new_path);
            $imagick->destroy();
        } catch (Exception $e) {
            $saved = false;
        }
    }

    // If conversion failed entirely, leave the original webp alone
    if (!$saved) {
        return $upload;
    }

    @unlink($file_path);

    $upload['file'] = $new_path;
    $upload['url']  = preg_replace('/\.webp$/i', '.jpg', $upload['url']);
    $upload['type'] = 'image/jpeg';

    return $upload;
}<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//jfinelaw.com/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://jfinelaw.com/post-sitemap1.xml</loc>
		<lastmod>2026-07-13T15:22:07+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://jfinelaw.com/post-sitemap2.xml</loc>
		<lastmod>2026-07-10T19:52:07+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://jfinelaw.com/post-sitemap3.xml</loc>
		<lastmod>2026-07-10T16:26:56+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://jfinelaw.com/post-sitemap4.xml</loc>
		<lastmod>2026-07-09T18:07:27+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://jfinelaw.com/page-sitemap.xml</loc>
		<lastmod>2026-07-13T15:51:25+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://jfinelaw.com/category-sitemap.xml</loc>
		<lastmod>2026-07-13T15:22:07+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://jfinelaw.com/local-sitemap.xml</loc>
		<lastmod>2026-06-25T20:54:28+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Rank Math SEO Plugin (c) Rank Math - rankmath.com -->