Awesome WordPress hacks to make your blogger life easier

WordPress hacks are always a popular topic here at Cats Who Code. Today, I have compiled hacks that will make your blogger life easier, by optimizing and simplifying how your WordPress blog works. Enjoy!


Hardcode to make WordPress faster

Hardcoding is generally not a good practice, however in the case of an established website, hardcoding your blog url, site url, template path and stylesheet path will make your blog run faster.

When a function such as bloginfo('url') is called, WordPress executes a query to your database to get the value, except if the value can be found on your wp-config.php file.
To hardcode those constants, edit wp-config.php and paste the following (Don’t forget to change the values!):

define('WP_HOME', 'http://www.catswhocode.com'); // blog url
define('WP_SITEURL', 'http://www.catswhocode.com'); // site url
define('TEMPLATEPATH', '/absolute/path/to/wp-content/themes/cwc5');
define('STYLESHEETPATH', '/absolute/path/to/wp-content/themes/cwc5');

Source: http://digwp.com/2009/07/optimize-wordpress-performance-with-the-wp-config-php-file/

Set HTML editor as the default

I know a lot of tech-savvy persons who don’t really like WordPress “visual” editor. Personally, I don’t use it because I’m used to writing HTML, and also because WYSIWYG editors are more likely to produce bad, not valid or dirty code.

If you prefer using the HTML editor, then what about making it your blog default? Just paste the line below into your theme functions.php file, and you’re done.

add_filter('wp_default_editor', create_function('', 'return "html";'));

Source: http://www.wprecipes.com/how-to-set-html-editor-as-the-default-in-wordpress

Make term edition a lot easier

For some reason, WordPress uploader won’t let you upload some filetypes, such as Textmate’s .tmCommand. If you need to upload those files to your WordPress blog, here is a very nice snippet that will allow you to do it.

Simply paste the following code on your functions.php file. If needed, you can add more file types by adding them on line 4, separated by a pipe (|)

<?php
function addUploadMimes($mimes) {
    $mimes = array_merge($mimes, array(
        'tmbundle|tmCommand|tmDragCommand|tmSnippet|tmLanguage|tmPreferences' => 'application/octet-stream'
    ));

    return $mimes;
}
?>

add_filter('upload_mimes', 'addUploadMimes');

Source: http://www.wprecipes.com/wordpress-tip-allow-upload-of-more-file-types

Remove autolinks in comments

Links in comments can be a good thing when they’re useful and relevant, but unfortunely lots of people are just leaving links in your comments in order to get clicks and backlinks.
As this became a recurrent problem on my blogs, I’ve looked for a solution and found a piece of code that will make urls appears as text, not as links.

As always, the code have to be pasted to your functions.php file.

remove_filter('comment_text', 'make_clickable', 9);

Source: http://www.wprecipes.com/wordpress-hack-remove-autolinks-in-comments

Easily modify contact info

I always wondered why WordPress still has a Yahoo and a AIM field for user contact information while nowadays, services like Facebook or Twitter became a lot more popular.

This simple hack will remove the AIM, Yahoo and Jabber fields and will replace them with Twitter, Facebook and LinkedIn. Just paste the code below in your functions.php file, and you’re ready to go.

function extra_contact_info($contactmethods) {
    unset($contactmethods['aim']);
    unset($contactmethods['yim']);
    unset($contactmethods['jabber']);
    $contactmethods['facebook'] = 'Facebook';
    $contactmethods['twitter'] = 'Twitter';
    $contactmethods['linkedin'] = 'LinkedIn';

    return $contactmethods;
}
add_filter('user_contactmethods', 'extra_contact_info');

Advanced users would probably enjoy this class which allow you to manage user contact info easily.
Source: http://thomasgriffinmedia.com/blog/2010/09/how-to-add-custom-user-contact-info-in-wordpress/

Leverage browser caching via .htaccess

One of the easiest way to improve your blog speed and general user experience is to leverage browser caching to reduce the number of http queries that the server needs to process. In fact, static files like images or PDF documents are not likely to change often so we can improve our blog speed by telling user browsers that they don’t need to download those files again if they’re already on the browser cache.

Open your .htaccess file (located at the root of your WordPress install) and paste the following. Remember to always make a backup before editing .htaccess.

## EXPIRES CACHING ##

ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"

## EXPIRES CACHING ##

Source: http://thomasgriffinmedia.com/blog/2010/11/how-to-leverage-browser-caching-in-wordpress-via-htaccess/

Enjoyed this article? Please consider donating: 3FVR5qaxYV8yAgNUUS7FC3o8c54YfDR5zK