WordPress Optimization Guide

After installing WordPress, you may tweak some of its default settings to optimize the performance, enhance the security and make it more SEO friendly. Here, I am presenting a complete guide to optimize a newly installed WordPress.

How to optimize your new WordPress Installation.

The suggestions listed down are only for self hosted WordPress blogs and not for the free ones hosted in WordPress.com. Also, please ensure that you keep a backup of the important files which will be used for editing.

1. Change WordPress Permalinks Structure for better SEO.

The default Permalink structure of WordPress is not optimized for SEO. But the good thing is that, it offers you a plenty of options for choosing a custom permalink structure.

Inside your WordPress dashboard, Navigate to Settings -> Permalinks and change your permalink structure. The recommended WordPress URL structure, from the perspective of SEO and performance is

/%post_id%/%postname%

The URL structure that you see here in tacni.com is using the format as below.

/%category%/%postname%/

Please note that the above tweak is only for a new installation. If you change the permalink structure for existing websites,  you will loose all the hard earned backlinks from Google, search engines, and other websites.

2. Disable post revisions in WordPress

WordPress introduced a very helpful Post Revision feature in WordPress 2.6, which helps you to track changes made to a blog post. Additionally, it allows you to roll back to a previous version of the post if required. However, the extra revisions increase the size of wp_posts table thereby increasing the database size and Page Load time.

To turn off the post revisions in WordPress you can add a couple of lines of code in wp-config.php which resides in the root directory of your WordPress installation.

define( ‘WP_POST_REVISIONS’, false);

If you want to retain this feature to some extent, you have the option of limiting the no of post revisions by adding the line below.

define( ‘WP_POST_REVISIONS’, 3);

3. Disallow indexing of WordPress directories

In WordPress, there are many virtual directories and php scripts from the wp-admin and wp-includes folders which end upindexed in Google and other major search engines. To prevent virtual directory from appearing in search results, open the robots.txt file that lies in the root of the WordPress installation.

Add the below lines which will block the search engine bots from indexing behind-the-scenes files.

User-agent: *
Disallow: /wp-admin/
Disallow: /wp-includes/
Disallow: /wp-content/themes/
Disallow: /wp-content/plugins/
Disallow: /wp-content/cache
Disallow: /feed/
Disallow: /category/*/*

4. Disable HTML formatting in WordPress comments

The comment section in WordPress acts as an HTML editor where users can post HTML tags. Although not recommended, it is good to disable the feature as it helps in maintaining a clean and uniform appearance, and at the same time it decreases spamming and a host of other problems. To disable HTML in WordPress comments, you can add this snippet of code to your functions.php file.

add_filter( ‘pre_comment_content’, ‘wp_specialchars’ );

5. Change the Auto-Save Interval for Posts

When you are editing a post in WordPress, it will auto-save the draft as you type. This feature helps in recovering your work in case of browser crashes. By default, the post get saved every 60 secs. However, if you want to adjust the default duration to longer delays in between auto-saves to say 120 secs(2 minutes) or 180 secs(3 minutes), then just add a line of code in wp-config.php file.

define( ‘AUTOSAVE_INTERVAL’, 120 );

6. Remove Query Parameters from URLs for better SEO

Too often, we get WordPress URLs appended with some extra query parameters by external websites and services that lie beyond our control. For instance, tacni.com/?search=wordpress or tacni.com/?ref=feedburner.com are different URLs by which people can still reach tacni.com.

This situation may adversely affect the SEO of your website and dilute your incoming links. Google may sometimes confuse them as separate URLs and thus mark it as duplicate content. You can check this in HTML Suggestions section of your Google

Webmaster Tools dashboard, where it will show up as duplicate title tags. To avoid this, open the .htaccess file that lies in the root of your WordPress Installation and add the following code above the mod_rewrite rule. It will strip the unnecessary incoming query or search parameters.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} !=””
RewriteCond %{QUERY_STRING} !^p=.*
RewriteCond %{QUERY_STRING} !^s=.*
RewriteCond %{REQUEST_URI} !^/wp-admin.*
RewriteRule ^(.*)$ /$1? [R=301,L]
</IfModule>

7. Track 404 Errors in Google Analytics

No webmaster wants a visitor to land up in a 404 error page. It hurts your brand , the conversions and your SEO effort. You can use events in Google Analytics to log your 404 errors and details like the referring site, location, etc.

Add this snippet of code inside your Google Analytics tracking code after the _gaq.push function.

<? if (is_404()) { ?>
_gaq.push([‘_trackEvent’, ‘404’, document.location.pathname
+ document.location.search, document.referrer, 0, true]);
<? }

8. Hide the secondary WordPress feed link elements

Every WordPress website has multiple RSS feeds like the blog feed, comments feed, category feeds, archive feeds. These feeds are indexed by search engines which are of no real value. If you don’t want to publicize your secondary feed links, add these line to your functions.php file.

remove_action(‘wp_head’, ‘feed_links’, 2);
remove_action(‘wp_head’, ‘feed_links_extra’, 3);

9. Implement Caching

Caching is a great technique to improve user experience and page speed of your blog. The easiest way to implement caching is by using a caching plugin like W3 Total Cache or WP Super Cache. These plugins will generally create .html files for each post instead of issuing server side and database queries.

10. Hide XML Sitemaps from Search Engines

Add the following lines of code to your .htaccess file to prevent the search engines to show your sitemap in search results pages.

<IfModule mod_rewrite.c>
<Files sitemap.xml>
Header set X-Robots-Tag “noindex”
</Files>
</IfModule>

11. Database Optimization

Advanced users who has the database skills can simply use PHPMyAdmin to optimize your WordPress database. For others, these two plugins WP DB manager and Yoast Optimize DB will help in optimization.

12. Prevent people from browsing WordPress directory structure

Add the following line to your .htaccess file that exists in the root of WordPress installation to prevent users from browsing your WordPress files and folders.

Options All -Indexes

13. Compress JS and CSS files

Compressing the JavaScript and CSS files of your WordPress website will give you a good improvement in page loading time as it decrease your overall page size. You can use the plugins below to achieve it.

JS compressor: Closure Compiler and Minify JavaScript

CSS compressor: Minify CSS and CSS Compressor

14. Disable File Editing inside WordPress

When you login to your WordPress Dashboard as an Admin, you can edit the PHP source code files associated with WordPress plugins and themes.  If you want to disable this feature, you can add this line of code in wp-config.php file.

define( ‘DISALLOW_FILE_EDIT’, true );

15. Delete all unused WordPress plugins and Themes

Remove all unused code like the WordPress themes and plugins which you don’t require for your website.  This will not only clear some space in the server but also ensure that we have less executable code.

Leave a Reply