Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adjust the HTML that WordPress generates for SVG so they are resized to fit their container
<?php
/**
* Replace WordPress standard SVG width of 1 with 100%
* @author Alain Schlesser (alain.schlesser@gmail.com)
*
* By default, WordPress renders all SVG files uploaded through the Media
* Uploader with both width and height at "1".
*
* @param string $output HTML output that Genesis has generated for a
* requested image
* @return string modified version of the HTML $output
*
* @see http://docs.garyjones.co.uk/genesis/2.0.0/function-genesis_get_image.html
* @see http://www.w3.org/TR/SVG/mimereg.html
*/
function as_avoid_tiny_svgs( $output ) {
// replace width of "1" with a new width of "100%" and height of "1" with a
// new height of "auto"
$output = str_replace(
'width="1" height="1"',
'width="100%" height="auto"',
$output );
return $output;
}
add_filter( 'genesis_get_image', 'as_avoid_tiny_svgs' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.