Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@topher1kenobe
Created January 19, 2014 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save topher1kenobe/8511994 to your computer and use it in GitHub Desktop.
Save topher1kenobe/8511994 to your computer and use it in GitHub Desktop.
Make WordPress image insert function use html5 figures
/**
* 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