Add custom value to wp-config

Hi, I want to ask about how can I add custom value into wp-config.

I have tried the code below:
Config::define(‘MY_CUSTOM_VALUE’, env(‘MY_CUSTOM_VALUE’));

I also have set the value inside .env, but when I use it the console said:
Use of undefined constant MY_CUSTOM_VALUE

Anyone have any idea how to do this?

For anyone wondering, this is the correct way:
Config::define(‘MY_CUSTOM_VALUE’, env(‘MY_CUSTOM_VALUE’));

And I already done it, but just a stupid mistake that I’m not copy the application.php to the server.

How to check if the config is applied or not, you can use wp-cli command:
wp config list

It will print all variables inside wp-config, and you can be sure the value is there.

4 Likes