I would like to add some custom config variables in the wp-config.php file (not in the functions.php). Then, I need to access to these variables in my templates.
What is the way to do that ?

  • Hi can you get answer of this question. please i need this functionality. thank you Apr 21, 2014 at 6:53
  • I accepted the following answer, just add your custom variable with a define
    – aguidis
    Apr 22, 2014 at 9:34
  • Just FYI these are more accurately "defined constants" and not "variables". Oct 13, 2020 at 10:07

1 Answer 1


Why do you need this?

In wp-config you can set defines. They will be accesible everywhere without needing to use globals. Define something: define('MY_DEFINE_NAME', 'THE_VALUE');.

Then in your templates you can show the value like this: echo MY_DEFINE_NAME;

Or set the value to a variable: $var = MY_DEFINE_NAME;.

  • Thank you for your quick answer. I need to store some page IDs. The page IDs depend of environments (dev, production etc...). Moreover the functions.php is subversionned contrary to the wp-config.php. This is why I need to store some datas in this file.
    – aguidis
    Aug 13, 2013 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.