k-isabelle
5/31/2018 - 4:29 PM

image_send_to_editor Wordpress Filter

image_send_to_editor Wordpress Filter

function xy_add_image_data($html, $id, $caption, $title, $align, $url, $size, $alt = '' ){

    $html; //contains the string you need to edit

    // get the permalink
    $parent = get_post_field( 'post_parent', $id );
    $permalink = get_permalink( $parent );
    // get image src
    $src = wp_get_attachment_image_src( $id, $size );
    // get image description
    $image_post = get_post($id);
    $desc= $image_post->post_content;

    $html = '<img class="align-' . $align . '" alt="' . $alt . '" src="' . $src[0] . '" title="'.$title.'" data-pinurl="'.$permalink.'" data-description="'.$desc.'">';
    if($url){
      $html = '<a href="' . esc_attr($url) . '">'.$html.'</a>';
    }
    return $html;
}

add_filter('image_send_to_editor','xy_add_image_data',10,8);