Support » Requests and Feedback » The wp-config.php file

  • Sean

    (@sean-h)


    After 10 years of working with WordPress, I have to say I’ve always found the wp-config file a little messy. We all get by editing it, but every time I do I have to scroll through lines and lines of comments, telling me stuff I’ve known for years already.

    So with some time on my hands, and music in my headphones, I went to work on 6 sites. And this is what I came up with:

    <?php
    
    /** Database credentials 
    */
    define( 'DB_NAME', 'xxx' );
    define( 'DB_USER', 'xxx' );
    define( 'DB_PASSWORD', 'xxx' );
    define( 'DB_HOST', '127.0.0.1' );
    define( 'DB_CHARSET', 'utf8' );
    define( 'DB_COLLATE', '' );
    $table_prefix = 'xxx_';
    
    /** Authentication - Unique keys and salts
    */
    define('AUTH_KEY',         '>]wQe{Jcro=c~EPrxXNyOb61j+Lo4B$]eBHe-{yqbW76F@t8hMEw|-ZnTB1G/}');
    define('SECURE_AUTH_KEY',  '.!M9rp.LcWq75H$}38&yT]iw+^n]vmm$Q!^[M?ZAYzO1(>B;&TyWfD v$*t+s!O=');
    define('LOGGED_IN_KEY',    'Scm,_/%!qEk-[6a_7g,F STnMJ+>B(m--wi5|q{rO!-79L6P<}iGRq:m2[9e}<S_');
    define('NONCE_KEY',        '+u_4KXk+Zm=8#HY$S,6 *fV$UA#cF/H*Ls56l+&^IkevpY;hMC2gxxg{sHPzO-F+');
    define('AUTH_SALT',        'H+Y*?$W78m#_Drl@p}h-O;?]x!{L4=TfS&BVTALIL(5q->bO5%<Xrz^%#bBPD6,j');
    define('SECURE_AUTH_SALT', '?+7:hJ4Ax{!/N%Q|dk+U]x{C57s?>~V/!;w>A.v+r)r5S9s>S|& >Hox3-9h,FZ~');
    define('LOGGED_IN_SALT',   'H$CzM3ZxOFQD>l jj5MgK(_c8rG{8^5qS9{da<s#{D#m2W>MmM:+T%b9fTF.`Hg_');
    define('NONCE_SALT',       '?N5zfam.;0O]+|,4:k2Bf;7|+M<A`qY]j5dq?EbqDJ+duD*J4hH&RcT=2uRGqXAU');
    
    /** Custom values
    */
    define( 'WP_DEBUG', false );
    define( 'WP_MEMORY_LIMIT', '512M' );
    define( 'WP_MAX_MEMORY_LIMIT', '704M' );
    define( 'WP_POST_REVISIONS', 15 );
    define( 'DISABLE_WP_CRON', true );
    define( 'WPP_CACHE_VIEWS', true );
    define( 'WP_CACHE', true ); // SiteGround Optimizer
    
    /** Sets up WordPress vars and included files 
    */
    @include_once('/var/lib/sec/wp-settings-pre.php'); // SiteGround WordPress management system
    require_once ABSPATH . 'wp-settings.php';
    @include_once('/var/lib/sec/wp-settings.php'); // SiteGround WordPress management system

    Ok, it looks a little weird in a narrow column, but from 96 lines down to 37 it is so much kinder to my eyes. I can now find and edit stuff that much quicker.

    When it comes to the order of things, some say it matters, but after moving stuff around, the sites I have done it on are still going fine. Tests are still ongoing at the time of writing.

    I even moved the table_prefix above the salts, right under the rest of the database credentials, in one neat block, with one simple title line in comments per block.

    In a bid to only have what is absolutely necessary in this file for the sake of simplicity, I even removed the ABSPATH to the WordPress directory, because that is now handled in wp-load.php It apparently has been for years already, according to a discussion on StackOverflow.

    Why have I done this? Because together with htaccess, these 2 files are the only ones I ever go into. We can go into and make changes in the others, but I think it’s common knowledge such changes will just get overwritten on the next update. The 2 mentioned files won’t be touched on updates. If/when plugins and other functions do make changes to either of those files and just randomly dump their rules, I simply move them to the appropriate block of similar rules.

    Do I expect WP Core to make changes to the default wp-config file? No, unless there are those who think it could do with a bit of simplification, for both newbies and advanced users alike.

    In the meantime, if/when I start a new site, I’ll just copy/paste/update credentials from a template I’ve saved in a text editor.

  • You must be logged in to reply to this topic.