/**
* Filter tags in post content to use WebP and srcset if available.
* Converts .jpg/.jpeg/.png to .webp if file exists, and adds srcset for responsive images.
*/
function codit_content_img_to_webp_srcset( $content ) {
if ( is_admin() || codit_is_elementor_active() ) {
return $content;
}
return preg_replace_callback( '/]+)src=["\']([^"\']+\.(?:jpg|jpeg|png))["\']([^>]*)>/i', function( $matches ) {
$before = $matches[1];
$src = $matches[2];
$after = $matches[3];
$webp_src = preg_replace( '/\.(jpg|jpeg|png)$/i', '.webp', $src );
$srcset = $webp_src . ' 1x, ' . $src . ' 1x';
// If WebP file exists, use for fallback
$webp_path = ABSPATH . str_replace( home_url( '/' ), '', $webp_src );
if ( file_exists( $webp_path ) ) {
return '';
} else {
return '';
}
}, $content );
}
add_filter( 'the_content', 'codit_content_img_to_webp_srcset', 14 );
/**
* Add srcset and WebP for featured images and attachment images.
*/
function codit_attachment_img_to_webp_srcset( $html, $id, $size, $attr ) {
if ( is_admin() || codit_is_elementor_active() ) {
return $html;
}
if ( preg_match( '/src=["\']([^"\']+\.(?:jpg|jpeg|png))["\']/', $html, $m ) ) {
$src = $m[1];
$webp_src = preg_replace( '/\.(jpg|jpeg|png)$/i', '.webp', $src );
$srcset = $webp_src . ' 1x, ' . $src . ' 1x';
$webp_path = ABSPATH . str_replace( home_url( '/' ), '', $webp_src );
if ( file_exists( $webp_path ) ) {
$html = preg_replace( '/]+)src=["\'][^"\']+["\']([^>]*)>/', '', $html );
} else {
$html = preg_replace( '/]+)src=["\'][^"\']+["\']([^>]*)>/', '', $html );
}
}
return $html;
}
add_filter( 'post_thumbnail_html', 'codit_attachment_img_to_webp_srcset', 12, 4 );
add_filter( 'wp_get_attachment_image', 'codit_attachment_img_to_webp_srcset', 12, 4 );
/**
* Minify inline JS output and add aggressive defer/async to all enqueued scripts except critical.
*/
function codit_minify_js_output( $buffer ) {
// Remove comments, whitespace, and collapse lines for inline ';
}, $buffer );
return $buffer;
}
add_filter( 'final_output', 'codit_minify_js_output', 20 );
// More aggressive script deferral: add async to all scripts except modernizr and critical
add_filter( 'script_loader_tag', function( $tag, $handle ) {
if ( is_admin() || codit_is_elementor_active() ) return $tag;
$critical = array( 'modernizr' );
if ( in_array( $handle, $critical, true ) ) return $tag;
if ( strpos( $tag, ' defer ' ) === false ) {
$tag = str_replace( ' src=', ' defer async src=', $tag );
}
return $tag;
}, 20, 2 );
Warning: Cannot modify header information - headers already sent by (output started at D:\InetPub\vhosts\nextolive.com\nextolive\wp-content\themes\codit\functions.php:1) in D:\InetPub\vhosts\nextolive.com\nextolive\wp-content\plugins\seo-by-rank-math\includes\modules\sitemap\abstract-xml.php on line 66
Warning: Cannot modify header information - headers already sent by (output started at D:\InetPub\vhosts\nextolive.com\nextolive\wp-content\themes\codit\functions.php:1) in D:\InetPub\vhosts\nextolive.com\nextolive\wp-content\plugins\seo-by-rank-math\includes\modules\sitemap\abstract-xml.php on line 69
Warning: Cannot modify header information - headers already sent by (output started at D:\InetPub\vhosts\nextolive.com\nextolive\wp-content\themes\codit\functions.php:1) in D:\InetPub\vhosts\nextolive.com\nextolive\wp-content\plugins\seo-by-rank-math\includes\modules\sitemap\abstract-xml.php on line 69
Warning: Cannot modify header information - headers already sent by (output started at D:\InetPub\vhosts\nextolive.com\nextolive\wp-content\themes\codit\functions.php:1) in D:\InetPub\vhosts\nextolive.com\nextolive\wp-content\plugins\seo-by-rank-math\includes\modules\sitemap\abstract-xml.php on line 69
Warning: Cannot modify header information - headers already sent by (output started at D:\InetPub\vhosts\nextolive.com\nextolive\wp-content\themes\codit\functions.php:1) in D:\InetPub\vhosts\nextolive.com\nextolive\wp-content\plugins\seo-by-rank-math\includes\modules\sitemap\abstract-xml.php on line 69
Warning: Cannot modify header information - headers already sent by (output started at D:\InetPub\vhosts\nextolive.com\nextolive\wp-content\themes\codit\functions.php:1) in D:\InetPub\vhosts\nextolive.com\nextolive\wp-content\plugins\seo-by-rank-math\includes\modules\sitemap\abstract-xml.php on line 69 https://nextolive.com/post-sitemap.xml2026-04-03T13:17:35+00:00https://nextolive.com/page-sitemap.xml2026-04-02T08:57:55+00:00https://nextolive.com/codit_service-sitemap.xml2026-03-24T06:19:10+00:00https://nextolive.com/portfolio-sitemap.xml2026-03-16T06:40:53+00:00https://nextolive.com/category-sitemap.xml2026-04-03T13:17:35+00:00