WordpressI’ve worked a lot with WordPress for the last two years and I improved my process over the time. I’ll share today the ones concerning the wp-config.php file which is created during the install on the root folder, you can have a look on your server, it should be there.

These tips are easy to put into practice and they’ll slightly improve the performances of your website.

First you need to generate unique keys for your WordPress Install, get them there, just copy what’s displayed on the page. This is important as they are the basis of the password protection system.

Let’s get started now, here is a sample wp-config.php file with comments:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Défines if we are on the production server (online) or no
define('_IS_PROD', true);

if (!defined('ABSPATH')) {
    define('ABSPATH', dirname(__FILE__) . '/');
}

//Definitions: DB Connection, Website's address
if (_IS_PROD) {
    define('DB_NAME', '********');
    define('DB_USER', '********');
    define('DB_PASSWORD', '********');
    define('DB_HOST', '********');
    define('CACHE_EXPIRATION_TIME', 3600);
    // Use the url of your website
    define('WP_HOME', 'http://dev.mathiasphilippe.com');
    //Change this one during the install for security (and readability) reasons
    $table_prefix = 'wp_';
} else {
    define('DB_NAME', '********');
    define('DB_USER', '********');
    define('DB_PASSWORD', '********');
    define('DB_HOST', 'localhost');
    define('CACHE_EXPIRATION_TIME', 600);
    define('WP_HOME', 'http://localhost/mathiasphilippe.com/www');
    $table_prefix = 'wp_';
}

define('WP_DEBUG', false);
define('WP_CACHE', true);
define('ENABLE_CACHE', true);
//define('DISABLE_CACHE', true);

You can now add constants to limit the number of times your website queries the database, it can really improve the global performances and reduce load time.

You can change the address of the “wp-content” folder also, some people do for security reasons, I would not advise to do so as it’ll almost surely lead to some plugins incompatibilities. But of course if the McGyver inside you tells you to try, feel free and enjoy. 🙂

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//Url of your website
define('WP_SITEURL', WP_HOME);
//Add your our "content" Folder, generally "wp-content"
define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
define('WP_CONTENT_URL', WP_HOME . '/wp-content');
//Add your our "plugins" Folder, generally "plugins"
define('WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins');
define('WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins');
//Do not forget to change these three lines if you change of theme
define('TEMPLATEPATH', WP_CONTENT_DIR . '/themes/name_of_your_theme');
define('STYLESHEETPATH', WP_CONTENT_DIR . '/themes/name_of_your_theme');
define('TEMPLATE_URL', WP_CONTENT_URL . '/themes/name_of_your_theme');

define('SAVEQUERIES', false);
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
define('WPLANG', 'en_US'); // Change this if you use a translated version

//Desactivate post revisions, it's up to you
define('WP_POST_REVISIONS', false);
define('AUTOSAVE_INTERVAL', 180);
//define('EMPTY_TRASH_DAYS', 7); // Once a week
// You can run http://blog.mathiasphilippe.com/wp-admin/maint/repair.php
define('WP_ALLOW_REPAIR', true);

// The Security Keys you obtained, read above for details
define('AUTH_KEY', '+tpM`0rXAEtwlQ+|fWj20aDiph}98oemJ`*{>RBa{D[W.VeGBk}lNgq:P1%+++Ur');
define('SECURE_AUTH_KEY', 'VC#k6y((O|UgDF-|)^i>x-n!8~-c^1A:&m|@/j#`%KU48x}$Slin*`!_c!8-9UvI');
define('LOGGED_IN_KEY', 'NBcm-.vbOK$N5-{u-] *`i|d(q$$ :%kF.snst2~z@}/^Uj+&S4+8vFBDDRDM6@-');
define('NONCE_KEY', '>+r5e|DaL%{=PY 7R2=LVo]nIk1DKC[-J3 EY35)WH.vw!0goUlz/jJxfwE3Vq_*KwHiL:cLp&v');
define('SECURE_AUTH_SALT', 'ZwcS>Pp%%P3[_S:X7g1VzNfZ/&!:yM}D6FFBR*,$+A$J1mpz|5jMfI*vUNEnw0;1');
define('LOGGED_IN_SALT', '/gMGR#0kS8n2L;Zr|XQ>?D+QfJ');
define('NONCE_SALT', '|YCO>0TwOZ+s5Ah^>&bt]d,Bj@mOl3(#ed~xO/_p.`L.HvY[-v^-{|^/q|c2q-12');

If you are designing your own theme or if you don’t mind changing some code in it, you can go a little further in order to gain in performances. These constants will save ressources and will help you not to repeat the same thing over your theme.

1
2
define("_SITE_NAME", "Mathias Philippe");
define("_SITE_DESCRIPTION", "Your partner for #webdevelopment, #seo & #socialmediamarketing");

In your theme, the following header code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<meta charset="utf-8" />
<title><?php wp_title(); ?></title>
<link rel="stylesheet" type="text/css" media="all" href="<?php echo get_template_directory_uri(); ?>/css/reset.css" />
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/style.css" />
<?php wp_head(); ?>
<?php if (is_singular()) wp_enqueue_script('comment-reply'); ?>
</head>
<body <?php body_class(); ?>>
<div id="header">
        <h1 id="logo">
            <a href="<?php echo home_url( '/' ); ?>"  title="<?php echo get_bloginfo('sitename'); ?>"><?php bloginfo('sitename'); ?></a>
       </h1>
...

would become:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!DOCTYPE html>
<html dir="ltr" lang="<?php echo str_replace('_', '-', WPLANG); ?>">
<meta charset="utf-8" />
<title><?php wp_title(); ?></title>
<link rel="stylesheet" type="text/css" media="all" href="<?php echo TEMPLATE_URL; ?>/css/reset.css" />
<link rel="stylesheet" href="<?php echo TEMPLATE_URL; ?>/style.css" />
<?php wp_head(); ?>
<?php if (is_singular()) wp_enqueue_script('comment-reply'); ?>
</head>
<body <?php body_class(); ?>>
<div id="header">
        <h1 id="logo">
            <a href="<?php echo WP_SITEURL; ?>"  title="<?php echo _SITE_NAMEN; ?>"><?php echo _SITE_NAMEN; ?></a>
       </h1>
...

Share your optimizations if you have some also. 🙂