Two useful WordPress hacks

Doorway at Pembroke College, Oxford

By the time anyone is reading this, I will be well on my way to Snowdonia with the Walking Club. Rather than make this the longest pause in blogging in recent memory (four days!), I have queued up some short entries with images.

This post is a fairly esoteric one, of interest only to people who are either using WordPress of thinking of setting up a WordPress blog. It details two little programming tricks that improve the WordPress experience.

Please note, everywhere [square brackets] are used, they should be replaced with pointy brackets in the actual code.

PHP hack 1: thumbnails

By default, when you upload an image with the WordPress web interface and insert it into a post as a thumbnail, it comes out a measly 160 pixels wide. 320 is what I use, and it is far more appealing. To make the change:

1) Download /wp-admin/admin-functions.php

2) Search for this line:

$max_side = apply_filters( ‘wp_thumbnail_max_side_length’, 128, $attachment_id, $file );

3) Change 128 to 320, or whatever you like.

4) Re-upload to your server

PHP hack 2: dealing with MySQL outages

Unless you are having problems setting your blog up, the only time you will see the WordPress error about being unable to access your SQL database is when it has crashed, over at your web host. There is nothing you can do until they fix it, and it tends to confuse visitors. Using this trick, you can give them a bit of an explanation:

1) Download /wp-admin/wp-db.php

2) Find the line:

[h1 id=”logo”][img alt=”WordPress” src=”< ?php echo $admin_dir; ?>images/wordpress-logo.png” /][/h1]

3) Below it add:

[p][strong][em]Name of your hosting provider[/em] Hosting Failure[/strong][/p]

[p]Some kind of explanation[/p]

4) Re-upload to your server

Author: Milan

In the spring of 2005, I graduated from the University of British Columbia with a degree in International Relations and a general focus in the area of environmental politics. In the fall of 2005, I began reading for an M.Phil in IR at Wadham College, Oxford. Outside school, I am very interested in photography, writing, and the outdoors. I am writing this blog to keep in touch with friends and family around the world, provide a more personal view of graduate student life in Oxford, and pass on some lessons I've learned here.

10 thoughts on “Two useful WordPress hacks”

  1. So few of your readers would have an interest in this… I just don’t see the point.

  2. The MySQL error hack no longer works for WordPress 2.1.3. At a less busy time, I will figure out how to alter it.

  3. WordPress 2.3 note

    The PHP script to be edited to change thumbnail sizes is now /wp-admin/includes/image.php

  4. Three important lines to add to the 404.php file in your WordPress theme:

    < ?php ob_start(); ?>
    < ?php header("HTTP/1.1 404 Not Found"); ?>
    < ?php header("Status: 404 Not Found"); ?>

    Here is an explanation of why

    Scroll to “Sending Proper Headers”

  5. That approach actually didn’t work for me.

    Here’s another method that actually worked for me:

    So how do you fix it? My friend Carl Hoerth figured it out and it’s actually very easy:

    1. You find the header.php file in your chosen WordPress theme
    2. You rename the file header.old
    3. You open header.old in a text editor
    4. Insert a blank line one line above the line that reads something like:
    < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional… 5. Insert:

    6. Save this edited file as your new header.php

  6. WordPress 2.1 Thumbnail Hack

    WordPress 2.1 has come with some really nice updates, however, like the previous versions, there is still one extremely frustrating element stopping one from reaching overall WordPress zen! When uploading an image of over 3 megapixels, WordPress does not automatically create thumbnails.

    The reason for this is apparently to do with the stability of the php code that does the thumbnail converting (I think!?). That said, I have been able to push this 3 megapixel limit much higher and have not experianced any problems.

    So, to make the change, open up the admin-functions.php file in /wp-admin folder.
    On line 2117 there is a line of code that says the following:

    $max = apply_filters( ‘wp_thumbnail_creation_size_limit’, 3 * 1024 * 1024, $attachment_id, $file );

    Change the number 3 in this line to a suitable number (such as 9).
    Now save the admin-functions.php file, and upload a nice large picture.

    WordPress 2.1 now creates a thumbnail of any image that you upload.

    Cheers, Nick

Leave a Reply

Your email address will not be published. Required fields are marked *