Leveraging AI to Supercharge Your WordPress Business Website
In today’s competitive digital landscape, every business website needs an edge to...
Add this code to your functions.php file to add the dimensions to the image object array for svgs.
add_filter( 'wp_get_attachment_image_src', 'fix_wp_get_attachment_image_svg', 10, 4 );
function fix_wp_get_attachment_image_svg($image, $attachment_id, $size, $icon) {
if (is_array($image) && preg_match('/\.svg$/i', $image[0]) && $image[1] <= 1) { if(is_array($size)) { $image[1] = $size[0]; $image[2] = $size[1]; } elseif(($xml = simplexml_load_file($image[0])) !== false) { $attr = $xml->attributes();
$viewbox = explode(' ', $attr->viewBox);
$image[1] = isset($attr->width) && preg_match('/\d+/', $attr->width, $value) ? (int) $value[0] : (count($viewbox) == 4 ? (int) $viewbox[2] : null);
$image[2] = isset($attr->height) && preg_match('/\d+/', $attr->height, $value) ? (int) $value[0] : (count($viewbox) == 4 ? (int) $viewbox[3] : null);
} else {
$image[1] = $image[2] = null;
}
}
return $image;
}
ACF, Coding Tips, Wordpress, WordPress Tips
Share
In today’s competitive digital landscape, every business website needs an edge to...
WordPress has come a long way since its humble beginnings in 2003....
In the ever-evolving landscape of website development, staying ahead of the curve...
A quick way to remove empty p tags from custom shortcodes in Wordpress. <?php add_filter("the_content", "the_content_filter"); function the_content_filter($content) { $block...
Fed up of getting the W3 Validator warning "The type attribute is unnecessary..."? Here is a handy bit of code to...
To allow the editor user role to have full access to Gravity Forms, simply add this code to your functions.php...