The article contains my practices that I use to speed up the work of the site on the WordPress platform or online store on WordPress + Woocommerce.
I want to warn you right away – this is not Google Page Speed.

Hosting for WordPress.

A lot of articles and recommendations have been written on this subject, so there is no sense to repeat it. Here are my practical tips briefly:

Virtual hosting is suitable for:

  • small site / blog / etc with low traffic
  • small online store + low traffic blog

VPS is suitable for:

  • corporate website / blog with average traffic
  • online store with up to 2000 items and average traffic

VPS settings – at least two processors and 4 gB of memory.

Dedicated server:

Here, fantasy is limited only by common sense, and the server should start with at least four processors and 8 gB of memory.

As a hosting provider, I recommend “HOSTPRO”, which I have been working with for more than ten years..

Hosting options.

Properly configured hosting is the half the speed of the site. I use the following settings:

PHP settings

  • PHP version from 7.2 or higher
  • Process memory (memory_limit) – 512
  • Script execution time (max_execution_time) 300 Zend OPCache Module

Zend OPCache Module

  • opcache.enable=1
  • opcache.validate_timestamps=1
  • opcache.revalidate_freq=60
  • opcache.max_accelerated_files=10000
  • opcache.memory_consumption=64
  • opcache.interned_strings_buffer=8
  • opcache.fast_shutdown=1

Memcached module
Igbinary module

  • igbinary.compact_strings

MySQL settings

There is a good article about configuration settings for MySql “Server Configuration Examples”https://ruhighload.com/mycnfexample

This is where I’d like to finish the setup of the server side, although there is still a lot of work for the system administrator.

Setting up the site

Theme for WordPress + Woocommerce

If a good hosting is 50% of success, then a well-optimized topic is the next 25% and the remaining 25% are plugins. There are many separate articles on choosing a topic, I recommend SHoptimizer

Plugins to speed up the site

PHP code to speed up the site

Here will be the insertions of php code, which must be added to the function.php of the child theme.  I hope everyone knows what a child theme is.

How to speed up an admin panel:

First part:

* Disable the forced verification of new versions of WP, plugins and themes in the admin panel so that it does not slow down when you haven’t entered for a long time…
* All checks will occur unnoticed through the cron or when entering the page: “Console > Updates”.

if( is_admin() ){
// disable update check
remove_action( 'admin_init', '_maybe_update_core' );
remove_action( 'admin_init', '_maybe_update_plugins' );
remove_action( 'admin_init', '_maybe_update_themes' );
remove_action( 'load-plugins.php', 'wp_update_plugins' );
remove_action( 'load-themes.php', 'wp_update_themes' );

add_filter( 'pre_site_transient_browser_'. md5( $_SERVER['HTTP_USER_AGENT'] ), '__return_true' );
}

The second part – it should be used very carefully, it disables styles and js scripts on those pages where there is no woocommerce

add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
//first check that woo exists to prevent fatal errors
if ( function_exists( 'is_woocommerce' ) ) {
//dequeue scripts and styles
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
wp_dequeue_style( 'woocommerce_frontend_styles' );
wp_dequeue_style( 'woocommerce_fancybox_styles' );
wp_dequeue_style( 'woocommerce_chosen_styles' );
wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
wp_dequeue_script( 'wc_price_slider' );
wp_dequeue_script( 'wc-single-product' );
wp_dequeue_script( 'wc-add-to-cart' );
wp_dequeue_script( 'wc-cart-fragments' );
wp_dequeue_script( 'wc-checkout' );
wp_dequeue_script( 'wc-add-to-cart-variation' );
wp_dequeue_script( 'wc-single-product' );
wp_dequeue_script( 'wc-cart' );
wp_dequeue_script( 'wc-chosen' );
wp_dequeue_script( 'woocommerce' );
wp_dequeue_script( 'prettyPhoto' );
wp_dequeue_script( 'prettyPhoto-init' );
wp_dequeue_script( 'jquery-blockui' );
wp_dequeue_script( 'jquery-placeholder' );
wp_dequeue_script( 'fancybox' );
wp_dequeue_script( 'jqueryui' );
}
}
}

Removing WP-Syntax

remove_action( 'wp_head','wp_syntax_head');

Invoking Contact Form 7 (if you have one) only on the pages, where it is used

// Deregister Contact Form 7 styles

add_action( 'wp_print_styles', 'aa_deregister_styles', 100 );
function aa_deregister_styles() {
if ( ! is_page( get_theme_mod( "header_contacts") ) ) {
wp_deregister_style( 'contact-form-7' );
}
}

// Deregister Contact Form 7 JavaScript files on all pages without a form
add_action( 'wp_print_scripts', 'aa_deregister_javascript', 100 );
function aa_deregister_javascript() {
if ( ! is_page( get_theme_mod( "header_contacts") ) ) {
wp_deregister_script( 'contact-form-7' );
}
}