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);
Related Posts:
- Javascript WP Object Documentation?
- Custom “Uploads” Dir: “Edit Image” in Media Library broken
- What is “open()” in MediaUpload?
- Restrict file types in the uploader of a wp.media frame
- Only displaying zip files with wp media
- Uppload image from another source wp.media
- Search media with javascript
- Media library not working with wp_editor() on the front end
- WordPress Media Library: Custom tab content displayed in “Media Library” tab
- Manually mark imported photo as selected in media library
- Is there a media_upload_tabs-similar filter to add tabs to the simple/featured image picker?
- How to open the add media dialogue it in a certain state / tab?
- Update media library attachments
- How to locate the js code and php code for certain function?
- How to validate image with specific height and width selection in media selector
- How to Get Post Meta in .Js File [duplicate]
- Insert HTML markup to page content from the Media Frame modal
- Issue migrating a checkbox-type meta field to the block editor
- add_attachment hook not firing on certain devices
- Kadane’s algorithm explained
- How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause()
- How do I make the first letter of a string uppercase in JavaScript?
- How to format a JavaScript date
- Download File Using JavaScript/jQuery
- Disabling and enabling a html input button
- How do I test for an empty JavaScript object?
- TypeScript React.FC
confusion - TypeError: Cannot read property ‘then’ of undefined
- Infinite Scrolling in Asp.Net MVC with jQuery / AJAX Issues
- What are the difference between $(document).bind(‘ready’, function) and $(document).ready(function() {})
- using lodash .groupBy. how to add your own keys for grouped output?
- Uncaught ReferenceError: google is not defined when trying to use Google Places API without a map
- Why is window.showModalDialog deprecated? What to use instead?
- Should I use JSLint or JSHint JavaScript validation?
- How can I print using JQuery
- Short circuit Array.forEach like calling break
- Angular: conditional class with *ngClass
- Failed to compile. Module not found: Can’t resolve ‘react-router-dom’
- How to send an email from JavaScript
- MissingSchemaError: Schema hasn’t been registered for model “User”
- classical inheritance vs prototypal inheritance in javascript
- Uncaught TypeError: Cannot read property ‘value’ of null
- How to measure time taken by a function to execute
- var.replace is not a function
- Uncaught TypeError: Cannot read property ‘call’ of undefined at __webpack_require__
- Async/await in componentDidMount to load in correct order
- Dynamically load JS inside JS
- Tainted canvases may not be exported
- How to open a URL in a new Tab using JavaScript or jQuery?
- How to sort an object array by date property?
- React router not showing browser history
- How to define DO NOTHING in JavaScript
- How to get the difference between two arrays in JavaScript?
- How can I check whether a radio button is selected with JavaScript?
- JavaScript button onclick not working
- What counts as CPU Intensive tasks (eg. sorting, searching etc?)
- HTML make text clickable without making it a hyperlink
- Uncaught ReferenceError: React is not defined
- How to get the browser viewport dimensions?
- What is the equivalent of Java’s System.out.println() in Javascript?
- How can I exit from a javascript function? [duplicate]
- Object doesn’t support property or method ‘addEventListener’
- How to fix javascript .toFixed is not a Function error
- jQuery checkbox checked state changed event
- Javascript, viewing [object HTMLInputElement]
- Implementing Isomorphic JavaScript (React JS) in WordPress?
- Any advantage of using wp_scripts and is_IE when enqueuing scripts
- TinyMCE in a div / textarea on frontend?
- Include Javascript as Plain (No file inclusion)
- Adding wp_ajax to a theme outside functions.php (on specific template page)
- Insert shortcode in post editor from javascript (Visual / HTML)
- WordPress problem with htmlentities
- Provide specific example for block variation
- Block editor: How to check if block editor has initialized and populated the data store?
- How to add a custom.js file for a child-theme in a swift way?
- Trigger JS in custom meta box if a featured image is loaded/exists
- WP REST API Post Status Using JavaScript
- var is undefined in a Gutenberg block
- Custom wp.editor.initialize settings ignored
- Why my javascript code not working for the dashboard of wordpress admin?
- Detect When User Reads Full Article? [closed]
- Got a TypeError after update and need to adapt found solution
- How to add classes and events to image in javascript using Gutenberg?
- How do you filter the list of states when country is selected? [closed]
- Display a div when post has a certain tag
- Implementing Webflow JS in WordPress
- This page can’t load Google Maps correctly [closed]
- Load images after page load
- How to stop javascript code being broken when going into visual editor
- WordPress opens js files as a catalog. Path is right [closed]
- Facebook fanbox problem
- Add Paypal button redirect to a specific page after completing
- wp-api Backbone JS Client fetch options
- Google Page Speed
- Can’t Listen to KeyDown in TInyMCE Iframe (jQuery) and Pass it to Parent HTML FORM
- How To Display Author Popup on Entry Meta (Genesis Framework)?
- Trying to deque some .js from source
- Custom JS doesn’t work after 4.9.9 update [closed]
- Is there any halfway decent documentation on the wp.media JS class?
- Create Youtube embed block with createBlock