Example robots.txt File for WordPress

Search engines are really skilled at finding content on the web, however sometimes they are just a little too skilled! When using WordPress you might think that you’d want people to be able to find everything on your site but that isn’t always the case. The truth is there are a lot of core files working away behind the scenes to make your blog work the way it does and when they contain secure data, they are the last thing you want showing up on the first page of Google!

Robots.txt is a file that was designed to tell search engines like Google when they shoudln’t be looking at a certain area of your site. You simply create a text file with the proper formatting and add it to your sites root directory, which in turn can tell search engines which content you don’t want them to explore. The code below is sample content robots.txt file that I’ve created based on my research of the latest WordPress security and SEO information.

User-Agent: *
Disallow: /cgi-bin/
Disallow: /wp-admin/
Disallow: /wp-content/plugins/
Disallow: /wp-content/cache/
Disallow: /wp-content/themes/
Disallow: /wp-includes/

To use the above example robots.txt all you need to do is open a basic notepad editor and copy and past in the code above. When you are done, save the file as robots.txt and upload it to the root or home directory of your WordPress installation.

Note: The file name must end in .txt rather than .doc or some other extension.

Move The Thesis Navigation Bar Below The Header

When you first install the Thesis theme you will notice that it places the navigation menu above the header by default. In many cases you will want this to appear below the header instead and as such you can use the following code can be used to move the Thesis navigation from it’s current hook to one to just below your header images etc.

Note: Like all thesis function snippets you can simply copy and paste this code into the Custom File Editor in your dashboard. You should place this code in your custom_functions.php file.

/* Move Thesis Navigation Below Header */
remove_action('thesis_hook_before_header' , 'thesis_nav_menu');
add_action('thesis_hook_after_header', 'thesis_nav_menu');

I hope you enjoy this snippet!

.htaccess Optimisation – Snippet Swipe File

I would only recommend that Advanced & Expert users use these snippets!

This small collection of .htaccess code snippets are things that I’ve picked up over my time on the web for very specific uses. The .htaccess file is very dangerous to the wbesites health f you do anything wrong so I highly recommend that you fully backup everything before starting to use any of this code.

1. To Remove the generic /category/ slug in your category URLs

RewriteRule ^category/(.+)$ http://<strong>www.yourblog.com</strong>/$1 [R=301,L]

Source: How to: Remove /category/ from your WordPress url

2. Stop Spammers in their Tracks with Comment Deny for No Referrers

RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*<strong>yourblog.com</strong>.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

Source: How to: Deny comment posting to no referrer requests

3. Ban Spammers from your site when you know their IP address

 order allow,deny
deny from 200.49.176.139
allow from all

Source: Banning a WordPress Spammer With .htaccess

How to Remove the Thesis Theme Attribution Link

If you’ve ever used the Thesis theme you will have seen that it adds a small credit link to the bottom of your websites page design. Whilst this is great for Chris Pearson and his team in terms of free backlinks, generally speaking most professional users and non tech companies would like to be able to remove this small advert from their site so here is the code to do it.

Note: Like all thesis snippets you can simply copy and paste this code into the Custom File Editor in your dashboard. You should place this code in your custom_functions.php file.

/* Remove Thesis Attribution Link (Developer License Holders Only) */
remove_action('thesis_hook_footer', 'thesis_attribution');

I hope you enjoy this snippet!