0

I am using the following code to wrap my images with figure when i send the images to the editor.

// Wrap the inserted image html with <figure>
    function html_insert_image( $html, $id, $caption, $title, $align, $url, $size, $alt ) {
      $src  = wp_get_attachment_image_src( $id, $size, false );
      $html = "<figure id=\"post-$id media-$id\" class=\"align-$align\">";
      if ( $url ) {
      $html .= "<a href=\"$url\" class=\"image-link\"><img src=\"$src[0]\" title=\"$title\" alt=\"$alt\" /></a>";
  } else {
      $html .= "<img src=\"$src[0]\" title=\"$title\" alt=\"$alt\" />";
  }
  if ( $caption ) {
      $html .= "<p class='wp-caption-text'>$caption</p>";
  }
      $html .= "</figure>";
      return $html;
  }
add_filter( 'image_send_to_editor', 'html_insert_image', 10, 9 );

But the title tag returns empty like title=""any idea how to solve my problem?

0

This is expected, title is no longer used. Have a look at where the function is called in source that eventually fires that filter:

$title = ''; // We no longer insert title tags into <img> tags, as they are redundant.
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.