Improving for iframe load times for WordPress Calls to Action
The Problem
WordPress Calls to Action currently loads CTAs in iframes which can cause a delayed load of the content in the iframe.
Even with caching enabled we call a redirect script that programatically disables caching so we can display the correct variation in a split testing scenario, which means that if you have a lot of plugins activated we could see delayed displays of up to 2-5 seconds.
The Improvement
Since CTAs are basically their own custom post type being loaded within an iframe we wanted a way to disabled plugins that are not related to the CTA plugin or any other plugin that the CTA might be dependant on related to our toolsets over at InboundNow.com
The Solution
WordPress has a hook called ‘option_active_plugins’ that can be accessed by plugin in the /wp-content/mu-plugins directory.
mu-plugins (must use plugins) are php files pasted directly into the /mu-plugins/ directory. They do not need their own subdirectory as they are usually meant to be single files. They also to not need to be activated or deactivated as having them in the mu-plugins directory will immediately activate them.
We wrote a mu-plugin that will disable all non-inboundnow plugins when loading a CTA in an iframe.
Installing the code below in the /mu-plugins/ directory will dramatically improves the load time of pages called with the _GET parameter.
The Code
<?php /* Plugin Name: Calls to Action - CTA Load Time Enhancement Plugin URI: http://www.inboundnow.com/cta/ Description: Disabled 3rd party plugins and themes in order to speed up CTA iframe render times. Version: 1.3.0 Author: Hudson Atwell Author URI: http://www.hudsonatwell.co */ $current_url = "http://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"].""; /* Listener for Thin Load */ if ( strstr( $current_url , '/cta/' ) ) { add_filter( 'option_active_plugins', 'wp_cta_thin_disable_plugin' ); function wp_cta_thin_disable_plugin($plugins) { $whitelist = array('cta/wordpress-cta.php','landing-pages/landing-pages.php','leads/wordpress-leads.php','marketing-automation/marketing-automation.php'); foreach ($plugins as $name) { if ( in_array( $name , $whitelist) || strstr( $name , 'inboundnow-' ) ) $whitelist_plugins[] = $name; } return $whitelist_plugins; } }