Avoiding Timeout When Exporting Large WordPress Sites

When exporting large WordPress sites with thousands of posts and comments, I occasionally run into an issue where the WordPress export tool times out before it’s finished building the XML export file. This can usually be remedied by updating the config files for Apache and PHP. Temporarily increasing the amount of time allowed for a single request should solve the problem. Note that you’ll need access to your server’s config files to make these changes. If you don’t have access, explain to your web host what you’re trying to do and they should be able to help you out.

Assuming you have access, here are some values that you can try:

In the Apache config file, try setting Timeout 300, which means that a single request is allowed to take up to 300 seconds to process before it’s shut down.

You’ll have to make a similar change in the PHP config file. That line will look like max_execution_time = 300. While you’re in there, you may also want to increase the maximum amount of memory available to PHP for a single request. memory_limit = 256M should do the trick.

After you’ve made your config updates, restart Apache so that they take effect. Now you should be able to export your site without any problems. Be patient, as it can take several minutes to export a large site. The values above will give you up to 5 minutes. If it takes longer than that, the process will continue to timeout and you’ll have to make the values even larger.

It’s important to note that after you’re done with the export you should change the settings back to their initial values. No ordinary request should take 300 seconds. Leaving the timeout values that high will allow poorly written scripts to tie up Apache processes for a long time, which will seriously impact your server’s performance.

Super Easy WordPress Breadcrumbs

Here’s a simple script to generate breadcrumbs for any page or custom post type that uses parent pages to establish hierarchy. I’ve opted to only show breadcrumbs on pages that have at least one parent. If your page doesn’t have a parent, nothing will show up.

To get started, paste this function into functions.php:

function easy_breadcrumbs($post) {
    $parent_id = $post->post_parent;
    if ($parent_id == 0) { return false; }
    else {
        $output = '';
        while ($parent_id != 0) {
            $ancestor = get_post($parent_id);
            $output = '<li><a href="'.get_permalink($ancestor->ID).'">'.$ancestor->post_title.'</a></li>' . $output;

            $parent_id = $ancestor->post_parent;
        return '<ul class="breadcrumbs"><li><a href="'.home_url().'">Home</a></li>'.$output.'</ul>';

To display the breadcrumbs, paste the following code into your template inside of the loop:

<?php echo easy_breadcrumbs($post); ?>

Now you have an unordered list. To make it look like you’d expect, you’ll need a little css. Something like this should do the trick:

.breadcrumbs {
	padding: 0;
	margin: 0;
.breadcrumbs li {
	display: inline-block;
	list-style: none;
.breadcrumbs li + li:before {
	content: ">";
	display: inline-block;
	margin: 0 .4em 0 .2em;

Uptime Robot WordPress Plugin

I’ve been using a simple, free uptime monitoring service called Uptime Robot lately to monitor a few of my sites. It will check up to 50 sites every 5 minutes to determine if they are online or offline, log any downtime events, and optionally notify you when your sites are down, all for free.

I wrote a quick WordPress plugin which creates a dashboard widget with your most recent Uptime Robot log entries. You can either monitor your entire account, or a single site. Just add the correct API key to the settings page.

You can download Uptime Robot for WordPress from the official plugin directory or through your WordPress Admin.

Create a Static Splash Page in WordPress

I know, splash pages are wrong, evil, and will probably bring about the downfall of society. But what if you need one anyway? Say, for example, you are preparing to launch a site based on wordpress but while you’re still putting it all together you don’t want visitors poking around. How can you create a static splash page to tell people that your site is coming soon (whatever that means?)

I found myself in just that situation recently. I looked around for a plugin to let me replace my index with a simple html document for a little while. I may write one yet, but for now a beautifully simple solution is doing the trick. Here’s what to do:

  • Create a blank file in your theme directory and call it something like splash.php.
  • Make it a page template by pasting in the following:
    Template Name: Splash Page
  • Write your static HTML. If you need to link to images or stylesheets, I suggest putting them in a subdirectory of your theme called something like splash. You can then reference them in your HTML using a bit of code like <img src="<?php bloginfo('template_directory'); ?>/splash/image.jpg" alt="" />. Notice the php which finds your theme directory for you so your theme remains portable.
  • Create a blank page and set it to use the custom page template you’ve created. You’ll find it under the Page Attributes menu. As of WordPress 3.1 it’s on the right side of the admin and looks like this image.
  • Under Settings > Reading set the front page to use a static page and select the new page you’ve created. The index of your website will now be your page template with no dynamic content and no other theme files included. Easy-peasy.

Because you never called get_header(), get_sidebar(), or get_footer() you can now have a totally static splash page while you’re tweaking a theme, editing content, and doing your WordPress business in secret behind the scenes. If you still want to pull in some content from WordPress (like the title and page content) you can even grab the loop from your existing page.php and use it in your splash page.

Load A Page Into A WordPress Theme Outside Of The Loop

I build a fair number of WordPress sites on small budgets for my employer, Union Street Media. Sometimes I need to give our clients an editable region in the sidebar, away from the main blog/page content. Here’s a quick and dirty trick I use to pull a page into a theme outside of the loop:

// must use a variable for page id
// http://codex.wordpress.org/Function_Reference/get_page
$id = 3;
$p = get_page($id);
echo apply_filters('the_content', $p->post_content);

You can get your page ID by editing the page. It will show up in the url (the ‘post=x’ portion.) It’s important to note that you have to pass a variable to the get_page() function. If you just pass an integer it will throw a fatal error. No need to go into why that is; just keep it in mind. get_page() essentially wraps get_post() so that function’s documentation is a good place to start if you want to learn what’s available to you.

This isn’t a particularly pretty solution, but it’s quick and it works well provided you know your page IDs and you’re not making a theme for distribution. I like to name my page something like ‘**Sidebar Content’ so it is easy to differentiate from regular pages.

WordPress 301 Redirect Plugin Released

I’m very pleased to announce that I’ve released my first WordPress plugin. It’s called Simple 301 Redirects and it does just what it says on the tin. It provides an interface for redirecting URL requests. It’s handy for when you’ve migrated a site to WordPress and are unable to maintain the URL structure. With Simple 301 Redirects you can redirect your old urls like “/about.html” to new, clean URLs like “http://www.yoursite.com/pages/about/” or whatever you like. Redirecting your old links to new destinations is important for preserving inbound links and pagerank after migrating a site. And this plugin does it in the easiest possible way I could think of.

You can read a little bit more about the plugin at its official home on this site or go straight to the WordPress plugin directory to download it. I hope you find it helpful!

Simple 301 Redirects Plugin Screenshot