Smiley Happy Coder

I'm a web developer with a love of technology and I'm a bit of an Apple geek

Adding the Post ID to the WordPress Admin area

In a large complex WordPress installation you can sometimes have a lot of pages and posts and sometimes it becomes hard to find anything. Being able to find a post by post ID in the admin area could be a bit benefit.

I’ve recently been working on a WordPress site that has over a hundred pages Read On >

Get the ID of the last record you inserted into WordPress with $wpdb

So lets say I’m adding records to a table and then I need to add records to a relational table. I need the ID to be able to reference the rows in my pivot table.

Thankfully WordPress makes it silly easy.

Read On >

Only include code on my WordPress home page

I have just added a slider to a WordPress theme. Generally you would just include the relevant JavaScript and CSS calls in the footer and header files of your theme. They would then be pulled through to your theme.

The big problem with this is these files will be called on every single page not just the home page where my slider is actually used. Read On >

Add a screenshot to your WordPress theme

There are some files that you need to include when building a theme, especially if you’re intending to release that theme into the wilds.

One of these files is the screen shot.

WordPress Screenshot Screenshot

Read On >

WordPress skewing Analytics stats

analytics
The other day I was checking my Google Analytics stats and I came across a strange thing.

In my stats there was a page URL showing which didn’t look right to me. The URL looked like this

/?page_id=213&preview=true

Read On >

Change WordPress’s nasty maintenance message

When WordPress goes into maintenance mode your site will display a horrible plain text message which reads

“Briefly unavailable for scheduled maintenance. Check back in a minute.”

The message is functional but little else. Thankfully you can change it.

Where’s the code?

Open the load.php file which resides in the wp-includes folder.

Scroll down to line 164 as at WordPress Version 3.1 and you will see the following code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title><?php echo /*WP_I18N_MAINTENANCE*/'Maintenance'/*/WP_I18N_MAINTENANCE*/; ?></title>

	</head>
	<body>
		<h1><?php echo /*WP_I18N_MAINT_MSG*/'Briefly unavailable for scheduled maintenance. Check back in a minute.'/*/WP_I18N_MAINT_MSG*/; ?></h1>
	</body>
	</html>

If the code above doesn’t appear at line 164, it is entirely possible that things could move in future releases of WordPress. In that case just search the load.php file for

<!DOCTYPE html PUBLIC

This should lead you to the correct code.

Making changes

As you can see the code is a very simple HTML page.

You can now edit this part of the code, being careful not to edit anything beyond the bounds of the <?php and ?> tags.

You could go as far as to build an entire page there with as much design as you like.

Have fun!

Does anyone else have any cool WordPress tricks?

Configuring WordPress’s permalink structure

Poor Link Structure

If you use WordPress then I’m sure that you’re aware that you can change the structure of the URL’s that WordPress creates. No?

Well I’m glad I wrote this post then.

On some blogs you will see URL’s that look kind of like this

http://smileyhappycoder.co.uk/?p=85

Well to be honest, and I’m sure you’ll agree, that’s not too pretty to look at. And worse, what would Google and other search engines make of it? Not a lot is the answer. Read On >

How to put WordPress into maintenance mode manually

Sometimes you’d like to put your wordpress blog into maintenance mode for a while. Say you’re doing a crucial update and you want to take the site down just for a few seconds. Here’s how to do it.

  1. Log into your FTP site and browse the the site’s home folder.
  2. Create a new file called “.maintenance”
    Don’t include the quotes and ensure you include the dot at the start
  3. Open up that file and add the following code to it
<?php $upgrading = time(); ?>

So now your site should be in maintenance mode for a while or basically until you remove the file.

The function uses the following sum to work out how long to stay in maintenance mode for

The time now = The time specified – 10 minutes

So in the above example when we are using the time() function the sum will always be within 10 minutes.

If for some reason you’d like to take your site down until a specified time you can do that by adding a time to the function.

<?php $upgrading = '123123123' ?>

In the above example 123123123 is the unix time stamp for the time you’d like to site to come back to life minus 10 minutes.

Manually take WordPress out of maintenance mode

So we’ve all been there.

You have just logged into your WordPress dashboard and there are a couple of plugin updates showing.

You dutifully click the plugins section and then choose to update the selected plugins. The little spinning doughnut starts whizzing away as if something is happening.

You go away and make a drink, have a natter to your other half and come back to the computer, the spinning doughnut is still doing it’s thing.

So the update has failed but there is nothing you can do. Your nice shiny WordPress blog is stuck in maintenance mode. Every single page you try to view shows the big dirty message.

Briefly unavailable for scheduled maintenance. Check back in a minute.

Read On >