PHP code example of inc2734 / wp-page-speed-optimization

1. Go to this page and download the library: Download inc2734/wp-page-speed-optimization library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

inc2734 / wp-page-speed-optimization example snippets



// When Using composer auto loader
new Inc2734\WP_Page_Speed_Optimization\Bootstrap();

add_filter( 'inc2734_wp_page_speed_optimization_defer_scripts', function( $handles ) {
	return array_merge( $handles, [
		get_template(),
		get_stylesheet(),
	] );
} );

add_filter( 'inc2734_wp_page_speed_optimization_async_scripts', function( $handles ) {
	return array_merge( $handles, [
		'comment-reply',
		'wp-embed',
	] );
} );

add_filter( 'inc2734_wp_page_speed_optimization_optimize_jquery_loading', '__return_true' );

add_filter( 'inc2734_wp_page_speed_optimization_do_http2_server_push', '__return_true' );
add_filter( 'inc2734_wp_page_speed_optimization_http2_server_push_handles', function( $handles ) {
	return $handles;
} );

add_filter( 'inc2734_wp_page_speed_optimization_output_head_styles', function( $handles ) {
	return array_merge( $handles, [
		get_template(),
		get_stylesheet(),
	] );
} );

add_filter( 'inc2734_wp_page_speed_optimization_preload_stylesheets', function( $handles ) {
	$wp_styles = wp_styles();
	$preload_handles = $wp_styles->queue;

	if ( in_array( get_template(), $preload_handles ) ) {
		unset( $preload_handles[ get_template() ] );
	}

	if ( in_array( get_stylesheet(), $preload_handles ) ) {
		unset( $preload_handles[ get_stylesheet() ] );
	}

	return array_merge( $handles, $preload_handles );
} );

// If `set-expires-header` customize setting
add_action( 'customize_save_set-expires-header', function( $customize_setting ) {
	if ( $customize_setting->post_value() === $customize_setting->value() ) {
		return;
	}

	\Inc2734\WP_Page_Speed_Optimization\Helper\write_cache_control_setting( (bool) $customize_setting->post_value() );
} );

// in functions.php
add_filter( 'inc2734_wp_page_speed_optimization_caching_sidebars', '__return_true' );

// in template
\Inc2734\WP_Page_Speed_Optimization\Page_Speed_Optimization\Helper\dynamic_sidebar( 'footer-widget-area' );

add_filter( 'inc2734_wp_page_speed_async_attachment_images', '__return_true' );

add_filter( 'inc2734_wp_page_speed_async_content_images', '__return_true' );