That function looks like the kind of thing that would slow down a site. 🙂
The first thing I’d recommend is that you not run that function on the front end. Run it when the image is uploaded and store the result in the database using wp_update_attachment_metadata
. You can then retrieve the data with wp_get_attachment_metadata
. An administrator/editor can swallow a 40 second lag. Your readers shouldn’t have to.
If you have a huge number of images and can’t loop over them to alter the metadata so you have to run that function on image display, save the data with wp_update_attachment_metadata
anyway so that it only has to run once.
Secondly, I would use get_post_mime_type
at the top of that function and exit if the attachment isn’t a GIF. Only a GIF can be an animated GIF right?
Related Posts:
- Auto delete WordPress images/thumbnails (all sizes) and featured after X days/hours, or similar?
- How to add a rel attribute to images that contains their categories?
- Automatically wrap multiple images in div
- Twentyten Child Theme: header images display messed up in admin panel
- Add attribute only to first image of every post via functions.php
- Replace image attributes for lazyload plugin on image elements with specific class
- How to crop image in WordPress with aspect ratio for any size of image
- Missing feature image link function
- When should you, and when should you not, use wp_list_pluck()?
- How to change the markup WordPress inserts for post images
- Woocommerce add to simple product attribute programmatically [closed]
- Programmatically Set First Image as Featured
- WP 4.4. responsive loads normal image after loading the responsive image
- opening links in new tab using – add_filter( ‘the_content’, ‘make_clickable’);
- How to add classes to images based on their categories?
- How to reduce original image quality on upload?
- Set image size on media and text block with a function
- Generating Responsive Background Image Sizes in PHP
- Set default options for inserting media
- Create thumbnail on PDF upload with Gravity Forms
- Remove images from get_the_excerpt
- Remove tag on my RSS Feed
- Use Exact Image Size using add_image_size
- Insert width & height attributes to all images displayed on each page
- Custom image size in Media Dropdown
- Theme-Config tab in admin Pannel?
- How to Add a Random Custom Gravatar in the WordPress Comments?
- Removing the first image in content
- Post thumbnail relative link and HTML modify
- How to add css class to image attached in all the posts?
- Add custom image size not working
- How to mass-delete inline styles in WordPress custom post type automatically?
- How would go about if I just want a temporary function?
- Remove the deleted users avatar from list
- How to call custom function from functions.php in site-wide template files?
- how to add an image to the footer?
- str_replace function in theme
- wp_get_attachment_image function size argument not working if I also add a custom class
- Right way to update widget on dynamic new input field
- Publish/Update post is changing image links from file url to post url
- Disable auto-resizing of uploaded images, but only for certain filename
- Best practices regarding the creation of custom widgets?
- Can you put a condition on add_image_size() depending on the width of the uploaded image?
- Remove after images
- Word Press – Dynamic Content [closed]
- Insert image in WordPress with HTML5 tag and caption function
- how can I just add to parent theme function(s) instead of redeclaring whole the function
- Can’t generate thumbnail images
- Skeleton Child Theme Add Icon Bar to Header Flex Grid
- Redirect to another page using contact form 7? [closed]
- Custom HTML markup
- How to hide image-url if no attachment?
- Use a shortcode to display custom meta box contents
- How to properly set custom logo size?
- How to Add Shortcode to html img code?
- The_content and Preg_replace in loaded Iframe [closed]
- Image Crop Not Working
- two search forms on the same page
- Use existing image sizes for WooCommerce
- Problem in using Customizer
- wp_get_attachment_image_src returns image on main domain, false on subdomain
- New checkbox in custom widget isn’t saving data
- Linking Javascript in functions.php file
- Retrieve First Image Function
- Featured Image keeps cropping
- Prevent creating multiple image resizes in twentytwelve template
- Conditional function for excluding first image from content, not working
- Function to check if custom page is used by page?
- Different image using srcset function
- Is it possible to limit number of files a non-admin user can upload via the WordPress media library?
- Auto delete content in specific folder inside media library
- Header menu aligned right on all pages except for single-post page [closed]
- How to update an image attachment’s alt text from a custom field when saving a post?
- large image size of 1440×1440 not pulling 2x of 2880×2880 image
- Hide author info in single posts by certain users
- Can You Set A Minimum Image Dimension For Resizing Images?
- Shortcode to insert default text and change one word throughout it?
- (Divi): How to make WordPress load images of specific size for Blurb modules on given page with a funciton?
- I want to customize the_posts_navigation function by replacing prev and next with images
- How would I correctly implement a new if statement in a child functions file?
- True email confirmation for registration (keeping unvalidated users from user table)
- restrict uploaded image size and fixed image display size
- Adding A New Widget to WordPress Disables the Existing Widgets
- How To Show Shortcodes In WordPress Custom Fields?
- Using Switch Statement to Change Image According to Last Digit of Topic ID
- Disable links to images only if link is an image
- Restricted images only for logged user. (hidden url)
- How do I integrate my Child Theme into a Custom Template?
- Shortcode to eliminate and replace with
- custom post with loading script per single post
- Open image size links in a page instead of direct image link
- Get Value of Custom Field
- restrict access to specific urls on a specific period of time
- child_of not working while searching
- Function to get thumbnail img source
- Removing Facebook contact field from user contact not working
- How to resize image from import image url?
- How to overwrite image if it already exists – WordPress, Gravity form
- Customizer cuistom CSS Priority ordre Issue
- Copy and Modified WooCommerce function is_coupon_valid [closed]