Skip to content

Instantly share code, notes, and snippets.

@topleague
topleague / Leverage-Browser-Caching.css
Last active December 14, 2017 17:30
Leverage Browser Caching
#Set caching on image files for 11 months
<filesMatch "\.(ico|gif|jpg|png|svg)$">
ExpiresActive On
ExpiresDefault "access plus 11 month"
Header append Cache-Control "public"
</filesMatch>
<filesMatch "\.(css|js)$">
ExpiresActive On
ExpiresDefault "access plus 1 week"
@topleague
topleague / font-awesome-cdn.php
Last active December 14, 2017 17:10
Installing Font Awesome without Render Blocking
<link href="https://opensource.keycdn.com/fontawesome/4.5.0/font-awesome.min.css" rel="stylesheet">
@topleague
topleague / google-fonts-wordpress.js
Created December 14, 2017 14:22
Install Google Fonts without Rendering Blocking
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.5.18/webfont.js"></script>
<script>
WebFont.load({
google: {
families: ['Source+Serif+Pro:400,600,700']
}
});
</script>
@topleague
topleague / gzip-compression-apache.php
Created December 14, 2017 14:42
Enable Gzip Compression in Apache Server
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
@topleague
topleague / gzip-compression-nginx.php
Created December 14, 2017 14:44
Enable Gzip Compression in Nginx Server
gzip on;
gzip_comp_level 2;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_disable "MSIE [1-6].(?!.*SV1)";
gzip_vary on;
@topleague
topleague / webp-conversion-wordpress.php
Created December 16, 2017 05:12
Convert PNG/JPG Files into WebP Format in WordPress
#Apache WebP Configuration
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{DOCUMENT_ROOT}/$1.webp -f
RewriteRule ^(wp-content/uploads.+)\.(jpe?g|png)$ $1.webp [T=image/webp,E=accept:1]
</IfModule>
<IfModule mod_headers.c>
Header append Vary Accept env=REDIRECT_accept
@topleague
topleague / display-image-file-size-wordpress.php
Created December 16, 2017 05:37
Display Image File Size in WordPress Media Folder
//* Get file size for all of your items in the Media library
//* URL: https://wordpress.stackexchange.com/questions/237131/display-image-file-size-in-media-library
add_filter( 'manage_upload_columns', 'wpse_237131_add_column_file_size' );
add_action( 'manage_media_custom_column', 'wpse_237131_column_file_size', 10, 2 );
function wpse_237131_add_column_file_size( $columns ) { // Create the column
$columns['filesize'] = 'File Size';
return $columns;
}
@topleague
topleague / display-image-dimension-media-library.php
Last active December 20, 2017 09:56
Show Dimensions in WordPress Media Library
//* Plugin Name: Show Dimensions in Library
function susanta_show_dimensions_size_column_register($columns) {
/* translators: Column name */
$columns['dimensions'] = __('Dimensions', 'show-dimensions-in-library');
return $columns;
}
function susanta_show_dimensions_size_column_display($column_name, $post_id) {
@topleague
topleague / spotwalla-embed-map-code.js
Created December 25, 2017 14:19
Embed SpotWalla Map on Your Site
<iframe
src='https://spotwalla.com/embed.php?id=54321abcd321&scale=on&zoom=default&refresh=no&hoursPast=0&showAll=yes'
width='100%'
height='600'
scrolling='no'
frameborder='0'>
Embedding failed because inline frames are not supported by your browser or the web server.
</iframe>
@topleague
topleague / custom-dimension-google-analytics.js
Created February 16, 2018 07:05
Set up a Custom Dimension in Google Analytics
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
// Creates an adblock detection plugin.
ga('provide', 'adblockTracker', function(tracker, opts) {
var ad = document.createElement('ins');
ad.className = 'AdSense';