• Skip to main content
  • Skip to footer

HeyRobot

Experts in development, SEO and technical optimisation of WordPress and React solutions

  • EnglishEnglish
    • DanskDansk
    • EnglishEnglish
  • Services
    • React SEO
    • React + WordPress solutions
    • Pagespeed Optimisation
    • WordPress custom development
    • WordPress premium plugins
    • Custom website development
  • About
    • Privacy Policy
  • Geek blog
  • Contact

5 Tips and tricks for better pagespeed in WordPress

Below you can find 5 tips and tricks that work for everyone, which is easy to implement and do not require anything other than that you use them;-)

1. Remove style loader tag from CSS

Place the following in your theme’s functions. php file

function hey_remove_style_id($link) {
	return preg_replace("/id='.*-css'/", "", $link);
}
add_filter('style_loader_tag', 'hey_remove_style_id',9999);

2. Remove the following, for overhead and unnecessary code

Place the following in your theme’s functions. php file

remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');

remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );

remove_action( 'wp_head', 'feed_links_extra', 3 ); // Display the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links', 2 ); // Display the links to the general feeds: Post and Comment Feed
remove_action( 'wp_head', 'rsd_link' ); // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( 'wp_head', 'wlwmanifest_link' ); // Display the link to the Windows Live Writer manifest file.
remove_action( 'wp_head', 'wp_generator' ); // Display the XHTML generator that is generated on the wp_head hook, WP version

3. Load JQuery from CDN

Place the following in your theme’s functions. php file

add_action( 'wp_enqueue_scripts', 'hey_load_scripts' );
function hey_load_scripts() {
	wp_deregister_script( 'jquery');
	wp_enqueue_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js#nodefer', false, '1.12.4');
}

4. Run JavaScript after your DOM is ready

Use the following wrapper for all of your JavaScript features, so do not require JQuery before it is ready

document.addEventListener("DOMContentLoaded", function(event) 
{
	jQuery(function($)
	{

	});
});

5. Defer all Java scripts that can be delayed

Place the following in your theme’s functions. php file

function hey_js_defer_attr($tag)
{
	if(!empty(strstr($tag,'gravityforms')) || !empty(strstr($tag,'stripe')) )
	{
		return str_replace( ' src', ' data-pagespeed-no-defer src', $tag );
	}

	if(strstr($tag,'#nodefer'))
	{
		$tag=str_replace( '#nodefer', '', $tag );
		return str_replace( ' src', ' data-pagespeed-no-defer src', $tag );
	}

	if ( is_admin() ) return $tag;
	return str_replace( ' src', ' defer="defer" src', $tag );

}


add_filter( 'script_loader_tag', 'hey_js_defer_attr', 99 );

Kim Frederiksen / 09/13/2019

Filed Under: Code snippets, Wordpress

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Talk to us

You can always connect with us for an informal conversation or an objective look at your project

Call us at +45 30 27 95 56 or write us at info@heyrobot.com

Footer

Virtual runs

Information

  • Privacy Policy

Contact

HeyRobot
email: info@heyrobot.com

(C) 2019 HeyRobot