0

I'm using WP 3.8 and Markdown on Save Improved plugin and have following code for outputing HTML5 tags when inserting images via Media Uploader:

function html5_insert_image($html, $id, $caption, $title, $align, $url, $size, $alt) {
  $src  = wp_get_attachment_image_src( $id, $size, false );
  $html5 = "<figure>";
  $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 );

And in editor output is fine, but on publish my code looks like this:

<p></p>
<figure>
<img src="image_link" alt="alt_txt">
<p></p>
<figcaption>caption_txt</figcaption>
<p></p>
</figure>
<p></p>

If I put div wrapper around figure then there are no empty paragraphs but I'm wondering why figure and figcaption aren't recognized as block elements? Also, this doesn't happen with wp-markdown plugin so it seems it's not markdown problem since both plugins use same parser.

When combining HTML and markdown in other ways, output is fine so I think that's not the issue.

  • Please update your installation before proceeding further. Current is 3.8 and as core doesn't support older versions... – kaiser Dec 17 '13 at 15:43
  • I finally got around to updating to 3.8 and testing again. Nothing's changed, problem remains... – Teo Dragovic Dec 20 '13 at 15:22
  • I guess that's a problem with wpautop(). Have you already asked the plugin author? – kaiser Dec 20 '13 at 15:29
  • yes, I posted question wp forums a while ago but got no response wordpress.org/support/topic/… – Teo Dragovic Dec 20 '13 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.