Skip to content

Instantly share code, notes, and snippets.

@michaelmusgrove
Created October 10, 2014 01:43
Show Gist options
  • Save michaelmusgrove/a0f6231b53626d2f60f3 to your computer and use it in GitHub Desktop.
Save michaelmusgrove/a0f6231b53626d2f60f3 to your computer and use it in GitHub Desktop.
Make images responsive - create a shortcode
[responsive]<img src="image_url" alt="alt" title="title" />[/responsive]
function responsive_images($atts, $content = null) {
return '<div class="image-resized">' . $content .'</div>';
}
add_shortcode('responsive', 'responsive_images');
Once done, open your style.css file and add those CSS rules:
@media only screen and (max-width:767px) {
.image-resized img {
width:100%;
height:auto;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment