Loading a widget after page load

I have a few non-wpmu plugins that load a youtube widget, a twitter widget, and a flickr widget. They all use the widgets_init action to load their code. My question is this: is there a way to change the action to load only after the entire window has already loaded? Can I tie it to a different action?

  • Sajid
    • DEV MAN’s Sidekick

    Hello Matt,
    Hope you are doing good today :slight_smile:

    If these are widgets then I don't think you can change their position to load a different location. This may cause some functionality issues.

    However, you can still try to load on wp_footer action hook but you may need to edit the PHP code of each plugin in order to do this.

    However, if I understand correctly, you may want to do this for site optimization. In this case, you can load scripts and styles of these plugins in footer by using Minification feature of Hummingbird plugin.

    Take care and have a nice day!

    Best Regards,
    Sajid - WPMU DEV Support

  • Matt
    • WPMU DEV Initiate

    Yeah, I already got the scripts/css minified and in the footer. What I was looking to defer was that these plugins load non-optimized images from a third party. I wanted those to load after the entire page loads. Wonder if I can use wp_loaded instead.

  • Denitsa
    • WordPress Warrior

    Hello Matt,

    Did you try loading those plugins asynchronously to improve page loading speed? That's best done by a third party plugin like Async JavaScript
    Many other caching plugins like W3 Total Cache are also offering this function.

    If you want to load just the images after the page loads (aka "lazy load" them) you'd need to use ajax or a third party plugin. The a3 Lazy Load plugin for example should enable lazy loading for your images and media.

    Let us know if this works for you!


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.