Last active
August 29, 2015 14:18
-
-
Save schlessera/d9de7fa35bc6c693dfe8 to your computer and use it in GitHub Desktop.
Adjust the HTML that WordPress generates for SVG so they are resized to fit their container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Replace WordPress standard SVG width of 1 with 100% | |
* @author Alain Schlesser ([email protected]) | |
* | |
* 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