2. This Presentations Covers:
• Optimization tips for WordPress developers releasing
their work for free in official repositories or somewhere
else
!
• Optimization tips for WordPress developers selling
themes or plugins on their own or through a
marketplace
2
3. Why Page Loading Time Matters
• Improved user experience
• Higher conversion rates
• SEO benefits
3
4. Things That Can Slow You Down
• Poor hosting
• No caching
• Non optimized content
• Problems caused by theme or plugins
4
6. Plugins Used in This Test
• Akismet
• BackWPUp
• Captcha
• Contact Form 7
• Google XML Sitemaps
• Jetpack by WordPress.com
• NextGEN Gallery by Photocrati
• Ultimate TinyMCE
• WooCommerce
• WordPress SEO
6
16. Key Problems Caused by Themes and
Plugins
• Longer page generation time
Hello, Two Worlds! - 19 database queries with Underscores vs. 79 “fully loaded”
• Too many HTTP requests
Hello, Two Worlds! - 3 JS and 1 CSS file with Underscores vs. 45 and 17 “fully loaded”
• Buggy code
16
17. In House Optimization - Things to Keep
in Mind
• Use transients for expensive DB queries
• Use transients for remote requests to external APIs
• Do not load scripts and styles in every page
17
18. Transients API
• Used to cache specific data that needs to be refreshed within a given
timeframe
• Uses object caching if available, otherwise stores values in options table
• set_transient() and set_site_transient()
• get_transient() and get_site_transient()
• delete_transient() and delete_site_transient()
18
23. Real-life Example
• When author box is added to single posts
and pages automatically
• When shortcode is used
• When widget is used
• When template tag is used
Selectively loading scripts and styles in Fanciest Author Box
23
25. function ts_fab_styles_needed() {
// Use helper functions to get plugin settings
$ts_fab_display_settings = ts_fab_get_display_settings();
/* Posts */
if ( is_single() && 'no' != $ts_fab_display_settings['show_in_posts'] )
return true;
/* Pages */
if ( is_page() && 'no' != $ts_fab_display_settings['show_in_pages'] )
return true;
...
/* Shortcode */
global $post;
if( is_singular() && has_shortcode( $post->post_content, 'ts_fab' ) )
return true;
/* Widget check is performed inside widget class */
return false;
}
25
26. Loading Scripts and Styles When
Widget Is Used
function __construct() {
$widget_ops = array(
'classname' => 'ts-fab-widget',
'description' => 'Fanciest Author Box ' . __( 'widget', 'ts-fab' )
);
parent::__construct( 'ts-fab-widget', 'Fanciest Author Box', $widget_ops );
if ( is_active_widget( false, false, $this->id_base ) ) :
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_fab_styles' ) );
endif;
}
function enqueue_fab_styles() {
wp_enqueue_style( 'ts_fab_css' );
wp_enqueue_script( 'ts_fab_js' );
}
26
27. Conclusion
• Use transients for caching
• Make your plugins and themes do only what they really have to, only when
they have to
• Don’t eat cake while you’re running on a treadmill