Last active
August 29, 2015 14:17
-
-
Save natejacobson/4aa2be3a7b30b577ac07 to your computer and use it in GitHub Desktop.
Normalize WordPress images and figures by auto wrapping images and exposing assigned image classes on figure
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
function imageWrap() { | |
$("article img").each( function() { | |
var img_classes = $(this).attr("class"); | |
var img_src = $(this).attr("src"); | |
if ( !$(this).parent().is("figure") ) { | |
$(this).unwrap("p").wrap('<figure class="figure-auto figure-back '+img_classes+'" style="background-image: url(\''+img_src+'\')"></figure>'); | |
} else { | |
$(this).parent("figure").removeAttr("style").addClass("figure-norm figure-back").addClass(img_classes).css("background-image","url('"+img_src+"')"); | |
} | |
}); | |
} | |
if ( $("body.single").length || $("body.page").length ) { | |
imageWrap(); | |
} | |
<style> | |
.figure-back { background-image: none !important; } | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment