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!):
view sourceprint?
1.define('WP_HOME', 'http://seo-ho.blogspot.com/'); // blog url
2.define('WP_SITEURL', 'http://seo-ho.blogspot.com/'); // site url
3.define('TEMPLATEPATH', '/absolute/path/to/wp-content/themes/cwc5');
4.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.
view sourceprint?
1.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 (|)
view sourceprint?
01.<?php
02.function addUploadMimes($mimes) {
03.    $mimes = array_merge($mimes, array(
04.        'tmbundle|tmCommand|tmDragCommand|tmSnippet|tmLanguage|tmPreferences' => 'application/octet-stream'
05.    ));
06. 
07.    return $mimes;
08.}
09.?>
10. 
11.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.
view sourceprint?
1.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.
view sourceprint?
01.function extra_contact_info($contactmethods) {
02.    unset($contactmethods['aim']);
03.    unset($contactmethods['yim']);
04.    unset($contactmethods['jabber']);
05.    $contactmethods['facebook'] = 'Facebook';
06.    $contactmethods['twitter'] = 'Twitter';
07.    $contactmethods['linkedin'] = 'LinkedIn';
08. 
09.    return $contactmethods;
10.}
11.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.
view sourceprint?
01.## EXPIRES CACHING ##
02. 
03.ExpiresActive On
04.ExpiresByType image/jpg "access 1 year"
05.ExpiresByType image/jpeg "access 1 year"
06.ExpiresByType image/gif "access 1 year"
07.ExpiresByType image/png "access 1 year"
08.ExpiresByType text/css "access 1 month"
09.ExpiresByType application/pdf "access 1 month"
10.ExpiresByType text/x-javascript "access 1 month"
11.ExpiresByType application/x-shockwave-flash "access 1 month"
12.ExpiresByType image/x-icon "access 1 year"
13.ExpiresDefault "access 2 days"
14. 
15.## EXPIRES CACHING ##
Source: http://thomasgriffinmedia.com/blog/2010/11/how-to-leverage-browser-caching-in-wordpress-via-htaccess/


1 nhận xét:

Samual said...

Thanks for sharing such a great Blog. Many people want to set up online business as part of their portfolio. It is indeed a cool thing to do and many people certainly want to reach as much customers as they can especially online.

White Label SEO

Post a Comment