Created
February 18, 2015 23:57
-
-
Save tomazzaman/b952b3f23dfdbf499e79 to your computer and use it in GitHub Desktop.
Insert image in WordPress with HTML5 <figure> tag and caption
This file contains 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 | |
// Don't include the opening tag | |
function html5_insert_image( $html, $id, $caption, $title, $align, $url, $size, $alt ) { | |
$src = wp_get_attachment_image_src( $id, $size, false ); | |
$html5 = "<figure id=\"post-$id media-$id\" class=\"align-$align\">"; | |
if ( $url ) { | |
$html5 .= "<a href=\"$url\" class=\"image-link\"><img src=\"$src[0]\" alt=\"$alt\" /></a>"; | |
} else { | |
$html5 .= "<img src=\"$src[0]\" alt=\"$alt\" />"; | |
} | |
if ( $caption ) { | |
$html5 .= "<figcaption>$caption</figcaption>"; | |
} | |
$html5 .= "</figure>"; | |
return $html5; | |
} | |
add_filter( 'image_send_to_editor', 'html5_insert_image', 10, 9 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No good here at all! If you try to remove image from editor FIGURE tags are not deleted.