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
- Can’t generate thumbnail images
- Move Custom Fields on General Settings Page to New Location
- media resize/crop possibilities?
- Skeleton Child Theme Add Icon Bar to Header Flex Grid
- Redirect to another page using contact form 7? [closed]
- different style sheet for just one page template
- Condition OR for current user ID
- Control the srcset much more (not all sizes in it each time)
- How to retrieve the current post’s generated featured image size?
- Way to store featured image width and height in two separate variables?
- srcset and custom field get_post_meta and wp_get_attachment_url
- Limit dimensions of “Full” size images
- Visual Composer creating own shortcodes with vc_map() to return simple Image
- Custom Behavior when Adding New Custom Post Type in Dashboard
- Where do I store custom functions that call custom page template files?
- Why There Is No “get content by ID” Function
- Custom HTML markup
- How to hide image-url if no attachment?
- Use a shortcode to display custom meta box contents
- Wp-query Order By problem
- Create custom function for hero image
- What are the meta fields for an attachment?
- Randomizing wp_tag_cloud() in child theme
- login_headertitle is deprecated since version 5.2.0
- How to append classname to body tag if guest user
- Where do I go to edit this area? [closed]
- Woocommerce image sizes missing from Appearance › Customize but not declared by theme
- How to properly set custom logo size?
- Replace plugin function with a custom function?
- Different favicon on different pages
- Need To Change WordPress Meta Tags… Includes wordpress shortcodes
- Need to convert image url to a Base_64 data url with wordpress function..
- How to Add Shortcode to html img code?
- The_content and Preg_replace in loaded Iframe [closed]
- How to add a new image size and apply it to posts only?
- Function to insert missing image size attributes into img tags
- Problem with images URL after filter applying
- Image Crop Not Working
- two search forms on the same page
- Function to replace comment’s accented characters before posting
- Use existing image sizes for WooCommerce
- Problem in using Customizer
- Insert a field with PREG_REPLACE – strange behaviour
- How to echo Widget Title in Custom Frontend-Template Box
- 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
- how to display a page before the home page
- loginout function customization
- Retrieve First Image Function
- Custom Image Size in Insert Media
- 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?
- Using add_image_size in functions.php to get original uploaded file
- get_image_tag() html output : empty src attribute
- implementing a centralized content “show-do-not-show” toggle?
- How would I make a function to dynamically determine if user is logged to change navigation menu text?
- How to display this meta data (an array) in form of a function (created with a custom write panel)?
- WordPress – using sessions?
- Need To Resize Images Exactly Without Losing Image Details
- Custom image sizes showing in Classic Editor only when upladed directly to post
- how can I change all wordpress media file url to custom cdn url?
- Different image using srcset function
- How to remove font awesome from loading in wp theme
- 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
- How to change images url in function.php?
- How to replace ACTION url from original wordpress login form?
- 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?
- Save_post – Warning: Cannot modify header information
- How to use WP conditional tag in a functions.php with OCEANWP Theme?
- Class parameter in get_avatar args doesn’t get added to output
- Modifying a WordPress Plugin
- CF7 select value get to function and reciept value from function
- large image size of 1440×1440 not pulling 2x of 2880×2880 image
- Hide author info in single posts by certain users
- External api call and make global variable for any page visitor enters , page-home, page, single etc
- CSS style and app.js not loading
- Can You Set A Minimum Image Dimension For Resizing Images?
- blank page with wp_get_attachment
- Parent category as WOOCommerce Categories widget title
- Extend WordPress Audio Widget to accept HLS (.m3u8) URLs
- 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?
- Images with overlay
- I want to customize the_posts_navigation function by replacing prev and next with images
- How Can I Concatenate A String With One Of My Custom Field Value Before Saving The Post?
- How would I correctly implement a new if statement in a child functions file?
- Woocommerce custom calculation function
- Remove all video attachment, both files and post/postmeta from database?