Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Adjust the HTML that WordPress generates for SVG so they are resized to fit their container
* Replace WordPress standard SVG width of 1 with 100%
* @author Alain Schlesser (
* 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
* @see
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.