I am trying to load preload-thumb into data-pil-thumb-url within the functions.php file so when a user edits a post with the TineyMCE it is automatically wrapped in a figure with the right classes. Whatever I do just returns blank.

add_action( 'after_setup_theme', 'images_theme_setup' );
function images_theme_setup() {
    add_image_size( 'preload-thumb', 300 ); // 300 pixels wide (and unlimited height)

function html5_insert_image($html, $id, $caption, $title, $align, $url) {
    $url = wp_get_attachment_url($id);
    $metadata = wp_get_attachment_metadata ($id);
    $width = $metadata['width'];
    $height = $metadata['height'];
    $image_attributes = wp_get_attachment_image_src( $url, 'preload-thumb' );

  $html5 = "<figure id='post-$id media-$id' class='pil align-$align'>";
  $html5 .= "<img src='$url' alt='$title' data-pil-thumb-url='$image_attributes' data-full-width='$width' data-full-height='$height' />";
  $html5 .= "</figure>";
  return $html5;
add_filter( 'image_send_to_editor', 'html5_insert_image', 10, 9 );
  • 1
    first argument for wp_get_attachment_image_src should be $id, not $url. – Milo Jul 7 '16 at 15:32

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.