CWC index .

Customize the Error Message on Wordpress

wordpress MOD

Once you have your WordPress blog up and successfully running, you might like to customize the error page that is seen on the occasional times that the host database cannot be contacted so that your visitors will see the same style of page as expected. It will look something like this:

[your page header]

WordPress

- no database connection

The database server for yourwordpressblogname at yourdomain.com (yourIPnumber) cannot be contacted. It is currently under maintenance and should be available soon.

In the meantime, please look through other areas of yourdomainname.com.

Perhaps you'd like to look at WordPress support as well.

[your page footer]

Before going any further, for security purposes, please check http://wordpress.org/ to ensure that you have the latest version of wordpress. If not, upgrade. Once you have done so and it is running correctly, here's how to customize your WordPress error page:

  1. First things first: backup and make a copy of wp-includes/wp-db.php.
  2. In a text editor, open wp-includes/wp-db.php.

    find
    $this->bail("
    Replace the above coding with
    $this->bail('
  3. find
    <h1>Error establishing a database connection</h1>
    <p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>$dbhost</code>. This could mean your host's database server is down.</p>
    <ul>
    	<li>Are you sure you have the correct username and password?</li>
    	<li>Are you sure that you have typed the correct hostname?</li>
    	<li>Are you sure that the database server is running?</li>
    </ul>
    <p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='http://wordpress.org/support/'>WordPress Support Forums</a>.</p>
    ");
    
    Replace the above coding with the words you would like your visitors to see when there is no connection to the WordPress database. Here is a suggestion:
    <h1><span>Word</span>Press</h1>
    <h2> - no database connection</h2>

    <p>The database server for <b>yourwordpressblogname</b> at yourdomain.com (<code>$dbhost</code>) cannot be contacted. It is currently under maintenance and should be available soon</p>

    <p>In the meantime, please look through other areas of <a href="/">yourdomainname</a>.</p>

    <p>Perhaps you\'d like to look at
    <a href="http://wordpress.org/support/">wordpress support</a> as well.</p>

    <!-- //
    <h1>Error establishing a database connection</h1>
    <p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can\'t contact the database server at <code>$dbhost</code>. This could mean your host\'s database server is down.</p>
    <ul>
    <li>Are you sure you have the correct username and password?</li>
    <li>Are you sure that you have typed the correct hostname?</li>
    <li>Are you sure that the database server is running?</li>
    </ul>
    <p>If you\'re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href="http://wordpress.org/support/">WordPress Support Forums</a>.</p>
    //-->
    ');

    Of course, you can type anything you like. Please note that apostrophes must be escaped! Instead of "can't", "host's" or "you're", add backslashes before each apostrophe: "can\'t", "host\'s" or "you\'re"

  4. find
    	function bail($message) { // Just wraps errors in a nice header and footer
    	if ( !$this->show_errors )
    		return false;
    	header( 'Content-Type: text/html; charset=utf-8');		
    	echo <<<HEAD
    	<!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>
    		<title>WordPress › Error</title>
    		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    		<style media="screen" type="text/css">
    		<!--
    		html {
    			background: #eee;
    		}
    		body {
    			background: #fff;
    			color: #000;
    			font-family: Georgia, "Times New Roman", Times, serif;
    			margin-left: 25%;
    			margin-right: 25%;
    			padding: .2em 2em;
    		}
    		
    		h1 {
    			color: #006;
    			font-size: 18px;
    			font-weight: lighter;
    		}
    		
    		h2 {
    			font-size: 16px;
    		}
    		
    		p, li, dt {
    			line-height: 140%;
    			padding-bottom: 2px;
    		}
    	
    		ul, ol {
    			padding: 5px 5px 5px 20px;
    		}
    		#logo {
    			margin-bottom: 2em;
    		}
    		-->
    		</style>
    	</head>
    	<body>
    
    Replace with

    function bail($message) { // Just wraps errors in a nice header and footer
    if ( !$this->show_errors )
    return false;
    header( 'Content-Type: text/html; charset=utf-8');
    echo <<<HEAD
    <!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>
    <title>yourdomain.com - yourblogname: WordPress › Error</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <style type="text/css">
    <!--
    @import url('http://www.yourdomain.com/yourstyle.css');

    #wordpress {
    background: #fff;
    color: #000;
    font-family: Georgia, "Times New Roman", Times, serif;
    padding: .2em 2em;
    width: 80%;
    margin:auto;
    border:1px solid #000;
    }

    #wordpress h1 {
    font-size: 18px;
    font-weight: lighter;
    padding:8px 8px 0 0;
    height:30px;
    display: inline;
    }

    #wordpress h1 span {color:#039;}

    #wordpress h2 {
    color: #039;
    display: inline;
    font-size: 1.1em;
    }

    #wordpress p, #wordpress li, #wordpress dt {
    line-height: 140%;
    padding-bottom: 2px;
    }

    #wordpress ul, #wordpress ol {
    padding: 5px 5px 5px 20px;
    }

    #wordpress #logo {
    margin-bottom: 2em;
    }
    -->
    </style>

    </head>
    <body>

    [your page header]

    <div id="wordpress">
  5. find
    	echo $message;
    	echo "</body></html>";
    
    Replace with

    echo $message . "</div>";
    echo <<<FOOT

    [your page footer]

    FOOT;
    echo "</body></html>";

Please make sure that you have inserted your own domain name in the appropriate spots. Replace [your page header] and [your page footer] with your site's header and footer. You can use ordinary HTML coding. Save the file as wp-db.php and upload it via ASCII to your wp-includes folder.

© llizard 2007

CWC reference pages . ASCII-art . illustrations and gif animations . llinks to ridiculously useless sites . home page