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', ''); // blog url
define('WP_SITEURL', ''); // site url
define('TEMPLATEPATH', '/absolute/path/to/wp-content/themes/cwc5');
define('STYLESHEETPATH', '/absolute/path/to/wp-content/themes/cwc5');


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";'));


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 (|)

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

    return $mimes;

add_filter('upload_mimes', 'addUploadMimes');


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);


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) {
    $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.

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.


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"



  • When a function such as bloginfo(‘url’) is called, WordPress executes a query to your database to get the value, excepted if the value can be found on your wp-config.php file.

    I really, really, REALLY wish people would stop spreading this misinformation. Especially people who constantly claim they DESERVE to get money for having a website.

    What you’ve written here is NOT how WordPress works. Even the biggest PHP noob wouldn’t write such inefficient code.

    WordPress builds an object with all the information about the site before it starts pulling post objects. The various info-querying functions merely go to this object and return the values therein.

    • If I made a mistake, sorry for that. I’ll investigate about it when I’ll have some time.
      That said, there’s no need to be to aggressive 😉

      • All the list post blogs and poorly researched info out there in the web design/development community is getting to me.

        • marco

          good advice brando, even if it comes from a guy who’s site is not standard, not accessible. but everyone here in internet still criticize every little thing in everyone else work.

          ps:tnx catswhocode for your tips
          (sorry for my english)

          • All I’m saying is do a little research before posting stuff. Especially if you’re on record being against Adblock because you believe you deserve money for posting freely-available code snippets.

          • Brando – On one hand, I hear you. On the other, let’s face it, there’s just too much to know. The beauty of a resource like CWC is that if a myth is publish – obviously by mistake – there’s enough expertise passing through to dispel such myths. Problem solved 🙂

            While you might be correct please try to show some empathy for your peers. Let’s face it, most of us are overworked, under paid, and live in a constant state of stress due to info overload.

        • mando

          You are talking like an expert, so why aren’t you create a blog and share your clever ideas. 🙂

    • from the Codex :

      WP_SITEURL, defined since WordPress Version 2.2, allows the WordPress address (URL) to be defined. The valued defined is the address where your WordPress core files reside. It should include the http:// part too. Do not put a slash “/” at the end.

      Setting this value in wp-config.php overrides the wp_options table value for siteurl and disables the WordPress address (URL) field in the Administration > Settings > General panel.

      NOTE: It won’t change the Database value though, and the url will revert to the old database value if this line is removed from wp-config. Use the RELOCATE constant to change the siteurl value in the database.

      If WordPress is installed into a directory called “wordpress” for the domain, define WP_SITEURL like this:

      define(‘WP_SITEURL’, ‘’);

      .. guess you are in the wrong here, no ?

    • You may well be correct but show some respect!

      Too many insanely ignorant people about these days.

      I’m guessing your position at PharrOut doesn’t involve contact with customers!

  • Khalid

    I really enjoy posts with WP-snippets/-tips like this one and I do always check them in case there’s something new to learn. =)

    • There’s some good tips, thanks !

      But to me, the one about the default editor is just useless, because you can set that in the admin panel 😉

      • Khalid

        That works only for you, because it’s a personal customisation. But when you use the snippet, it will change the preferences of all users/members.

        • And what if the other users want to use the visual editor ?

          • Khalid

            Then it’s ‘just useless’, like you said. =)

          • I felt the same exact way at first until recently I needed to disable the visual editor for only one page. The reason: WP was removing an “/div” if a user switched from Visual to HTML which was extremely important for layout reasons(obviously). I then added code stemming from this tip that checked for a certain post ID and forced the HTML editor only for that page revision.

            The tip came in very handy even after I questioned its usefulness.

  • Jacques Livoix

    Cool post. And great job for a PHP noob! I really wish people will start their own site instead of criticizing the work of the others.

  • Bob

    I’m particularly interested in making WordPress faster. I’ve been hearing a lot about how Google punishes sites that are slower. Not sure if this is true or not, but might as well be safe than sorry!

    • There are a lot of ways to make WordPress (and sites in general) faster. Nothing he’s listed here does a damn thing for speed except for the local caching bit at the end — but that’s standard affair. Then again so is everything I’ve listed next…

      Look into server-side caching plugins (page and database), using a content delivery network, GZIP your content before sending, minify your HTML/CSS/JS files, etc.

      • Leo


        Maybe you are right, but the agressive tone you use in your replies do not help you here. A bit more respect would be appropriate. Just sayin.

      • True about the GZIP compression, really makes the loading time faster. Recently tested on a heavy wp site, worth it!

  • I’m in wordpress business and already know some of the hacks and will try some of them from here.
    off the topic you’ve offered some of the good links to me (source taken from)

  • Some hacks are very handy and specially modifying user contact info inside wp-admin. Thanks for nice tricks.

  • myshock

    Bonjour Jean-Baptiste
    i noticed that “Hardcode to make WordPress faste” hack can cause css display problems when using WPTouch plugin (mobile phones).
    I contact you when i found the issue.
    Je suis un peu full en ce moment et n’ai pas vraiment pris le temps de regarder. Je pense pas que ce soit bien grave 😉 A bientôt.

  • Adding code to .htacess is always a challenge, when you are not familiar to the file. Sometime back I was trying to make my WordPress site fast by using the ‘Expires Caching’ on .htacess, but it seemed to be not working. Somehow, I was successful in implementing some caching, but now I will try your code. Hope it will help to make the site performance on Google Pagespeed better.Thanks a lot for sharing.

  • Thanks for the one about removing links in comments.

    Should be helpful against those who pass Akismet 🙂

  • Got to bookmark this page! Thanks for taking the time to share this. I love the link removal from comments as well, will use it for sure!

  • Interesting post, thanks for your tips and insight.

  • Hi I have one question, Is Hard coding will help in Shared hosting?

    • Xps

      Hard coding will definitely help, especially if you’re limited to a shared hosting web server. If you’re hard coding, the server only has to send text, which the web browser can quickly display. If you’re using scripts, the server and web browser have more work to do so the display time will be increased.

      I remember writing a mod for phpBB3 a couple years ago and it was deemed unacceptable because I hard coded text instead of using variables. It’s nice to see hard coding becoming acceptable again.

      I was thinking about implementing the .httaccess caching mod, but then decided against it. I set my web browser to delete cache pretty frequently in order to save disk space and overall computer efficiency, and it sounds like others are being more conscious of this too. Think programs like CCleaner. In the end, it won’t matter if you tell browsers to keep the cache for a year or even a month because they’re cleaning it even more frequently.

  • Nice post!

    I like the removing links from comments tip, it will probably reduce the PR leak!

    Comments are shocking though, but it’s ok.. it’s not a perfect world after all!

  • there are loads of other methods too. like minifying the js and css files, and incorporating them into small number of files. incorporating all images into a single image, using a cdn, and many more.

  • Xps

    My comment was deleted? That’s a bummer. I guess you disagreed with the comment I left about the .htaccess file.

    • I do not delete comment if I disagree with them (Read the first comment for example!)
      I delete comments which contain links, or large portion of unformatted code.

      It can also happen that I accidentally delete a comment. You’re welcome to post it again in that case. I’ll be careful 😉

      • Xps

        No hard feelings. I’ve found a number of blog owners delete legitimate comments which reference multiple points in the article and reader comments either because they’re having trouble distinguishing between legitimate and spam or are anti-competitive. Thanks for acknowledging my comment as not many do. You can delete this threaded comment and I’ll repost my reply to Madav. =)

  • I’ll try your “Remove autolinks in comments” for sure!
    It seems to be the best way to avoid spam in comments.

    • Xps

      I’m finding an increase in what the WordPress Codex calls “Stealth spam.” The comment itself doesn’t contain any keywords or links. It actually looks like a user praising the article or asking a question (albeit vague). The spam comes either from keywords as the poster’s name or the URL. (link intentionally avoided to not be ironic)

      I disagree with their suggestion of clicking the postor’s link to verify it because it could be malicious. Instead, check it with Google and then their cache version of the site to get an idea of what it really is before you visit it.

      I’m deleting a number of stealth spam comments as we speak, about 25 of them so far this evening. Looks like I’ll be spending tomorrow investigating or writing a spam deterrent script.

  • Its much better if those tags are not hard coded in php. It wastes precious resources and the loading time of the page. Its much easier to code in html. And also, html editor is the one to use, since we have to insert many html tags here and there.So visual editor can be a problem.

  • define(‘WP_HOME’, ‘ ‘); looks smart.

    But if you use WP Super Cache, doesn’t it make the same thing?

    I mean if you use WP Super Cache, do you really need these hacks?

  • I generally find W3 Total Cache better than WP Super Cache. It definitely speeds things up a little. The Google Page Speed firefox plugin is handy little tool if your concerned that a page is loading too slow.

  • Dominor Novus

    Regarding hard-coding wp-config.php, is there a security benefit in addition to a speed benefit? Does the speed benefit still stand in light of Brando’s comments)?

  • I don’t know a damn thing about coding but I do not one thing, if you do not put your energy and effort into running a highly successful blog like this, then SHUT THE HELL UP about a person making a mistake. I mean who in the world is perfect. Also, look the blog up on to see how successful they are. Do you think they become successful by misleading people? Huh, no! They are human like everyone else and I am sure the best programmer in the world makes mistakes and does not know everything about coding. From what I can tell, this community is awesome and most communities are like families so it’s just not wise coming into someone house or neighborhood and start speaking so rudely to people who bust their butt to provide relevant content to it’s readers. Kudos to blog authoer, kudos to the community, and Brando, I will pray for you and not condemn but if you are not going to say anything nice to the people here, then please keep it to yourself. 🙂

  • I like how to remove autolinks in comments, I’ll use it right away. thanks for your share.