Two useful WordPress hacks

2007-03-09

in Daily updates, Geek stuff, Internet matters

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

Report a typo or inaccuracy

{ 9 comments… read them below or add one }

Anonymous March 13, 2007 at 11:08 am

Ack! That looks tricky.

R.K. March 24, 2007 at 12:20 am

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

Milan April 10, 2007 at 11:11 am

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.

Anon April 11, 2007 at 6:36 pm

You may want to have a look at this: Small hack in Wordpress thumbnail creation

Milan November 3, 2007 at 6:29 pm

WordPress 2.3 note

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

Milan January 3, 2008 at 11:49 pm

The same file must be edited in WordPress 2.3.2.

Milan February 21, 2008 at 4:55 pm

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”

Milan February 21, 2008 at 4:59 pm

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

Anonymous March 1, 2008 at 9:56 am

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 Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

{ 1 trackback }

Previous post:

Next post: