Skip to content

Instantly share code, notes, and snippets.

@metaylimpo
metaylimpo / defer example.php
Last active Jun 8, 2020
Example how to defer js in Wordpress with function.php file
View defer example.php
<?php
if (!is_admin()) {
add_filter( 'script_loader_tag', function ( $tag, $handle ) {
if ( strpos( $tag, "jquery.js" ) ||
strpos( $tag, "leaflet.js") /*||
strpos( $tag, "add any script you want" )*/ ) {
return $tag;
}
return str_replace( ' src', ' defer="defer" src', $tag );
@metaylimpo
metaylimpo / .htaccess
Last active Dec 2, 2020
Example of wordpress .htaccess file for several optimizations and other things
View .htaccess
#DO NOT COPY\PASTE. Take only what you need carefully.
#The following code is just a few **examples** of optimizations that you can do in .htaccess file.
# HTTPS forced
<IfModule mod_rewrite.c>
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
View speedup elementor.php
<?php
// disable google fonts
add_filter( 'elementor/frontend/print_google_fonts', '__return_false' );
// add font-display swap to elementor custom fonts
add_filter( 'elementor_pro/custom_fonts/font_display', function( $current_value, $font_family, $data ) {
return 'swap';
// you can also play also with $current_value & $font_family for specific requirments
}, 10, 3 );
@metaylimpo
metaylimpo / functions.php
Last active Feb 2, 2022
Example of wordpress theme function file for several optimizations
View functions.php
/*
DO NOT COPY\PASTE. Take only what you need carefully.
The following code is just a few **examples** of optimizations that you can do in functions.php file.
*/
<?php
// disable google fonts
add_filter( 'elementor/frontend/print_google_fonts', '__return_false' );