Skip to a section of this page:

WordPress

A few notes on using/customising WordPress.

Disabling WordPress’ slap-happy approach to <br /> tags

These instructions tested under WordPress 2.0.2

WordPress loves to add <br /> tags all over the place. To stop the madness, open this file: /wp-includes/functions-formatting.php and change the following line (around line 57) from:

function wpautop($pee, $br = 1) {

to:

function wpautop($pee, $br = 0) {

This doesn’t remove any functionality, it just sets the default WordPress behaviour to not add <br /> tags everywhere.

Ensuring that WordPress’ keeps <code /> blocks sacred

These instructions tested under WordPress 2.0.2

If you leave a blank line in a code block, WordPress will helpfully add <p></p> tags in.

This will mess up your code (and invalidate your HTML!)

If you want your code blocks to be sacred, open this file: /wp-includes/functions-formatting.php and find the following line (around line 76):

$pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') .  stripslashes(clean_pre('$2'))  . '</pre>' ", $pee);

Then add the following line underneath, like this:

$pee = preg_replace('!(<pre.*?>)(.*?)</pre>!ise', " stripslashes('$1') .  stripslashes(clean_pre('$2'))  . '</pre>' ", $pee);
$pee = preg_replace('!(<code.*?>)(.*?)</code>!ise', " stripslashes('$1') .  stripslashes(clean_pre('$2'))  . '</code>' ", $pee);

Now WordPress will treat code blocks with the same degree of respect you do.

Preventing WordPress from adding <p> tags completely

If you are a HTML control-freak, you can prevent WordPress from adding any nasty <p> tags to your posts.

Open this file: /wp-includes/functions-formatting.php and find the following line (around line 65):

$pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end

Then comment the line out (with or without the maniacal comment):

# NO MORE NASTY <p> TAGS!!! buahh haa haa haa
# $pee = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "<p>$1</p>\n", $pee); // make paragraphs, including one at the end

Now you have complete control over your HTML.

Moving a WordPress installation

If you move the installation, you may lose the ability to login to the admin area. This SQL query will restore functionality, by correcting the relevant URL options:

update wp_options
    set option_value = 'http://newsitelocation.com/goes/here/' 
    where option_name = 'home' or option_name = 'siteurl';

If your Wordpress installation is not in the same directory as your home page, you will need to set these options to different values:

update wp_options
    set option_value = 'http://newsitelocation.com/wordpress/' 
    where option_name = 'siteurl';
update wp_options
    set option_value = 'http://newsitelocation.com/' 
    where option_name = 'home';

NOTE: your options table may have a different prefix, the default is ‘wp_’.

WordPress and MarsEdit

This is really not difficult to setup, but in case anyone like me, neglected the documentation only to struggle setting up MarsEdit to work with your WordPress blog, here’s the gist of it (current for WordPress 1.5.1 and MarsEdit 1.0):

  • Select WordPress from the Software dropdown list.
  • The RPC URL is http://yourWordPressURL/xmlrpc.php
  • The Blog ID is admin (I believe anything will do here)

I don’t believe Blog ID is important for us WordPressers.
From the MarsEdit Help manual:

The Blog ID is often your username or a number that identifies your weblog. Different systems have different ways of letting you find out what the Blog ID is.