For some time now i have been building up many snippets within “Sublime Text” that i use on a day to day basis whether its for wordpress or else most of the snippets can be used time and time again. So i thought i would share some of the most useful pieces of code for any wordpress install you should us:

1. The configuration file for wordpress
When you first setup your wordpress website, there are a few items you should update on your config file, being:
Authentication key wordpress
– Setting up your home and siteurls
– Defining other key features of wordpress, such as autosaving, revisions (which trust me is really handy for any client), debug and more.

Here is the default code i use on a day to day basis for any client (i’ve created this into a snippet for easy access, preventing myself having to recode this each day):
define(‘WP_POST_REVISIONS’, 10 );
define(‘AUTOSAVE_INTERVAL’, 60);
define(‘EMPTY_TRASH_DAYS’, 7);
define(‘WP_ALLOW_REPAIR’, true);
define(‘WP_HTTP_BLOCK_EXTERNAL’, false);
define(‘WP_DEBUG’, true);
define(‘WP_MEMORY_LIMIT’, ‘256M’);
define(‘WP_HOME’,’http://example.com’);
define(‘WP_SITEURL’,’http://example.com’);

2. WordPress compression
So you want to compress your files on your website, but don’t know how? well here is some important code you can use to apply to your htaccess file for your website (if you don’t see the htaccess in your ftp route folder, make sure to create one as “.htaccess”):
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddType x-font/otf .otf
AddType x-font/ttf .ttf
AddType x-font/eot .eot
AddType x-font/woff .woff
AddType image/x-icon .ico
AddType image/png .png


ExpiresActive on

# Media: images, video, audio
ExpiresByType image/gif “access plus 0 month”
ExpiresByType image/png “access plus 0 month”
ExpiresByType image/jpg “access plus 0 month”
ExpiresByType image/jpeg “access plus 0 month”
ExpiresByType video/ogg “access plus 0 month”
ExpiresByType audio/ogg “access plus 0 month”
ExpiresByType video/mp4 “access plus 0 month”
ExpiresByType video/webm “access plus 0 month”

# CSS and JavaScript
ExpiresByType text/css “access plus 0 year”
ExpiresByType application/javascript “access plus 0 year”
ExpiresByType text/javascript “access plus 0 year”


Header append Cache-Control “public”

3. Don’t downgrade your images on upload to wordpress
So many developer out there might know WordPress doesn’t use 100% quality for your images, as it saves on space? So that’s great and all for loading time, but i’ve come across many websites that require nothing less than 100% quality to show off their high-end products. So here is a very easy fix, just open up your functions file and whack this code below in your file:

function bd_image_quality() {
return 100;
}
add_filter( ‘jpeg_quality’, ‘bd_image_quality’ );

4. Always find your wordpress site has a copyright and year set
Every wordpress website i have worked on I have found that every time there is a copyright and year set by default which is static to the theme, I use this code ever time for this reason, which outputs the copyright logo and the current year (making sure your websites always up to date to the current year):
©

5. Useful code i have saved as a snippet
I regularly are in need of creating an if statement for pages on wordpress, whether its a template we are using for multiple pages on the website but only want to show a certain item on one of the pages. So instead of going to the wordpress library every time we have created a useful snippet which we can pull in every time to display something like:

or you might need to output a post type query and don’t have the code to hand, we created this simple snippet:


We also find every website includes buttons for pushing them important clients to the correct places, now do you find that them buttons when press always show that ever annoying blue glow around the buttons, for this reason we again created a useful snippet we use every time for all website, hope this would be useful for yourself:
input:focus
{
outline:none;
}

We also have created many snippets with “Sublime text” that we use all the time including for plugins such as ACF (Advanced custom fields) which is really useful for any developer.

6. Making sure your websites to the highest quality
Time and time again i come across websites online that have been designed and developed never to the best quality they can be, so from experience i have found to be very useful are:
– Upload imagery for your website 1.5x bigger than you need.
– Upload icons on 2x the size of the icon, so the icons are retina for all devices.

Having high quality images can reduce your websites loading speed, but making sure you save the image for web and us some useful tools such as https://imagecompressor.com/ can help you reduce the images and not loose that all important quality.

For icons, being there pretty much small touches on your website that help the design, if you don’t have these icons to hand, double the size of what you need, i would highly suggest using a website like https://fontawesome.com/ which allows you to download the icons and use as code in your website (pretty simple to install). This then gives you that ever important quality aspect in your website design.

Leave a Reply