I got it solved….
function filter_image_send_to_editor($html, $id, $caption, $title, $align, $url, $size, $alt) {
$animatedGif = (bool) get_post_meta($id, 'animated_gif', true);
if($animatedGif){
$gifCoverImgUrl = get_post_meta( $id, 'animated_gif_cover_url', true );
// build my GIF player
if(isset($gifCoverImgUrl) && $gifCoverImgUrl != ''){
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$src = $xpath->evaluate("string(//img/@src)");
$html="<img class="gifplayer" src="".$gifCoverImgUrl.'" data-gif="'.$src.'" />';
}
return $html;
}else{
// do nothing and return normal image tag string
return $html;
}
}
add_filter('image_send_to_editor', 'filter_image_send_to_editor', 10, 8);