GFX9.COM share New wp-config tweaks you probably don’t know, you can download now.

The wp-config.php file: One of the most loved WordPress feature for some, one of the worst nightmares for others.

There are countless tips and tricks in a plethora of articles, and you can't get enough of them; however, this article is aiming to be different. In this article, we're going to get familiar with eight new wp-config tricks that are less known than functionality such as turning off post revisions, increasing the memory limit, or other similar features.

Don't forget to backup your installation! The tips in this article do not change any database values nor do they play with any files (except wp-config.php, of course) so you can just download a copy of your wp-config.php file, but you can backup your database and files to make sure. Better safe than sorry—frequent backups are always good!

1. Setting a Default Theme for New WordPress Installations With WP_DEFAULT_THEME

Let's say you're a freelance web designer (or a web design agency) who uses a base WordPress theme for almost every client of yours. Wouldn't it be great if you don't have to change the theme from "Twenty-Something" to your "Awesome Base Theme" every time you create a new WordPress installation?

Well, the WP_DEFAULT_THEME constant has you covered:

define( 'WP_DEFAULT_THEME', 'default-theme-folder-name' );

You may ask: "How am I supposed to set a default theme by editing the wp-config.php file when that file is created while installing WordPress?" Excellent question, but we're not going to change the wp-config.php file this time: Instead, we're going to insert the code above into the wp-config-sample.php file!

I'm not talking about editing and renaming the file like it's 2006, I'm talking about editing the file and leaving it like that: WordPress can detect the changes and additions inside the wp-config-sample.php file (except the database credentials) and use them while installing your fresh copy of WordPress.

Neat, right? I haven't found any web page mentioning this hidden gem (and I found this technique by accident), so this tutorial might be the first time this feature is covered.

You may have your reasons to prevent WordPress from updating itself: Maybe you're a developer who needs to work on many versions of WordPress simultaneously, or your website is on a highly-unstable server that requires you to be extremely careful.

Whatever the case may be, we're here to offer you the solution of disabling automatic updates for WordPress:

define( 'AUTOMATIC_UPDATER_DISABLED', true );

3. Enabling the "Trash" Feature for Media Files With MEDIA_TRASH

Ever screamed in a high-pitched voice and cursed for seven minutes straight, after deleting a media file when you're not supposed to delete it? I know I did, before learning this WordPress constant:

define( 'MEDIA_TRASH', true );

Set it and you're never going to have to worry about deleting a media file—except if you disabled WordPress' "trash" feature altogether by setting the EMPTY_TRASH_DAYS constant to "0".

WordPress has file type restrictions when uploading files into the Media Library. You can't upload anything except images, documents, audio or video files—and it's good for security. But what if you're an independent software developer and want to upload new releases of your software—are you going to have to use an FTP client every time you update your software?

Nope, you just need to define the ALLOW_UNFILTERED_UPLOADS to ALLOW_UNFILTERED_UPLOADS like this:

define( 'ALLOW_UNFILTERED_UPLOADS', true );

This code doesn't allow every user to upload every file type, though. Only administrators are allowed to upload whatever they want.

6. Setting WPLANG Dynamically in Multilingual Websites

If you have a multilingual website and need your website to change the language of your theme and your administration panel, you can do a little trick to detect a visitor's browser language and define the WPLANG constant based on that information.

First, you need to create a wp-lang.php file and fill it with the code below, then save it in the same directory wp-config.php is in:

Then, in the wp-config.php file, replace the line where WPLANG is defined with the line below:

require_once( dirname( __FILE__ ) . '/wp-lang.php' );

And voilà! Your visitors can now change the language of your theme and admin panel by simple clicking buttons with a lang=fr_FR URL parameter.

If you're using a plugin that requires a WordPress.com API key (like Jetpack or Akismet) and have lots of WordPress websites to maintain, it might be a little bit annoying to enter your WordPress.com API key every time you install that plugin.

There's an easy way, though. You can define your API key in the wp-config.php file as a constant:

define( 'WPCOM_API_KEY', 'YourKeyHere' );

Check if your other favorite plugins have this feature. Plugins like SlideDeck and Gravity Forms support defining their API keys as a constant, too.

8. Redefining Allowed HTML Tags From Scratch With CUSTOM_TAGS

There's a function in WordPress, wp_kses() which, according to WordPress Codex:

"...makes sure that only the allowed HTML element names, attribute names and attribute values plus only sane HTML entities will occur in $string".

You have to rewrite each variable below. You can just copy & paste the variables in wp-includes/kses.php, then edit the code you pasted.

Credit: OttoPress.com

Conclusion

About two years ago, I wrote the post Conquering the wp-config.php File—11 Good Practices and it was one of the most popular WordPress posts that time. And two years later, I'm sharing another wp-config-related post, but this time, I chose to share tips that you may never even heard about.

I really hope you like it.

What about you, do you know any good wp-config tricks? Post a comment to share your experience! And if you liked the post, don't forget to share!