Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Custom Media Meta fields to alter the generated image HTML that is inserted into a post for my animated GIF image player?

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:

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

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress