Created
January 19, 2014 22:42
-
-
Save topher1kenobe/8511994 to your computer and use it in GitHub Desktop.
Make WordPress image insert function use html5 figures
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
/** | |
* Swap Default TinyMCE Tags for Figure Tags on Images | |
*/ | |
function html5_insert_image( $html, $id, $caption, $title, $align ) { | |
$title = esc_attr( $title ); | |
$caption = sanitize_text_field( $caption ); | |
$id = absint( $id ); | |
$url = esc_url( wp_get_attachment_url( $id ) ); | |
$align = esc_attr( $align ); | |
// check to see if we have a caption | |
if ( trim( $caption ) != '' ) { | |
$caption_class = ' wp-caption'; | |
} | |
$html5 = '<figure id="post-' . $id . ' media-' . $id . '" class="align-' . $align . $caption_class . ' post-img">'; | |
$html5 .= '<img src="' . $url . '" alt="' . $title . '" class="wp-post-image">'; | |
if ( trim( $caption ) != '' ) { | |
$html5 .= '<figcaption class="wp-caption-text">' . $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