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. Force-update the meta variable first set using `var [ meta, setMeta = useEntityProp( ‘postType’, postType, ‘meta’ );`
  21. How can I generate a rainbow circle using HTML5 canvas?
  22. What’s the difference between “{}” and “[]” while declaring a JavaScript array?
  23. What does “javascript:void(0)” mean?
  24. For-each over an array in JavaScript
  25. How to delete a cookie?
  26. What is TypeScript and why would I use it in place of JavaScript? [closed]
  27. How do you use the ? : (conditional) operator in JavaScript?
  28. Which equals operator (== vs ===) should be used in JavaScript comparisons?
  29. are there dictionaries in javascript like python?
  30. How to do associative array/hashing in JavaScript
  31. How to make a discord bot create an invite for every server it joins?
  32. ES6 Map in Typescript
  33. addEventListener vs onclick
  34. “Uncaught SyntaxError: Cannot use import statement outside a module” when importing ECMAScript 6
  35. How do I check if an array includes a value in JavaScript?
  36. JavaScript document.getElementById().value logs empty value
  37. How do I color a hexagonal grid such that it doesn’t have neighbors of the same color?
  38. How to format a JavaScript date
  39. What does href expression do?
  40. map function for objects (instead of arrays)
  41. Wait 5 seconds before executing next line
  42. Failed to load resource: the server responded with a status of 404 (Not Found)
  43. How to check whether a string contains a substring in JavaScript?
  44. Check if a string has a certain piece of text [duplicate]
  45. Kadane’s algorithm explained
  46. What is console.log?
  47. Dynamically creating charts of each row in an HTML table with chart.js
  48. Failed to load resource: the server responded with a status of 404 (Not Found)
  49. How to convert a string to an integer in JavaScript?
  50. Maximum call stack size exceeded error
  51. How to change CSS using jQuery?
  52. How to properly use jsPDF library
  53. How to reload a page using JavaScript
  54. How can I do string interpolation in JavaScript?
  55. Can I use complex HTML with Twitter Bootstrap’s Tooltip?
  56. Start script missing error when running npm start
  57. How do I redirect to another webpage?
  58. How to round to at most 2 decimal places, if necessary?
  59. What is VanillaJS?
  60. Invariant Violation: Objects are not valid as a React child
  61. How do I make the first letter of a string uppercase in JavaScript?
  62. How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause()
  63. window.location.href and window.open () methods in JavaScript
  64. Invariant Violation: Objects are not valid as a React child
  65. What’s the difference between using “let” and “var”?
  66. Angular: conditional class with *ngClass
  67. How do I make the first letter of a string uppercase in JavaScript?
  68. Loop through an array in JavaScript
  69. How to format a JavaScript date
  70. What does this symbol () => mean in Javascript? [duplicate]
  71. How do I redirect to another webpage?
  72. Google reCAPTCHA V3.0 not working. “ERROR for site owner: Invalid key type”
  73. How to round to at most 2 decimal places, if necessary?
  74. Google Chrome Uncaught (in promise) DOMException while playing AUDIO
  75. Define a global variable in a JavaScript function
  76. “SyntaxError: Unexpected token < in JSON at position 0"
  77. How to add a class to a given element?
  78. Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
  79. Javascript split regex question
  80. Cross-Origin Read Blocking (CORB)
  81. What is Virtual DOM?
  82. How can I remove a specific item from an array?
  83. How can a Discord bot create a hyperlink in a Discord message in an embed or in general? [closed]
  84. Find object by id in an array of JavaScript objects
  85. jQuery append() vs appendChild()
  86. How can I access and process nested objects, arrays or JSON?
  87. How to you store data for each discord user in the discord server?
  88. How to get all place details from a Place Details Request using Google Places API Web Service?
  89. How to make a word underline in Markdown
  90. Cannot set property ‘innerHTML’ of null
  91. Creating multiline strings in JavaScript
  92. How to replace innerHTML of a div using jQuery?
  93. SyntaxError: Unexpected token o in JSON at position 1
  94. Uncaught ReferenceError: $ is not defined?
  95. Cannot read property ‘addEventListener’ of null
  96. Uncaught ReferenceError: jQuery is not defined [duplicate]
  97. ChartJS beginAtZero, min, max doesn’t work
  98. How do I check whether a checkbox is checked in jQuery?
  99. Babel 6 regeneratorRuntime is not defined
  100. How to use Redirect in the new react-router-dom of Reactjs
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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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