最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to create custom variables in the wp-config

programmeradmin1浏览0评论

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 ?

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 ?

Share Improve this question edited Mar 2, 2020 at 13:10 SherylHohman 8419 silver badges14 bronze badges asked Aug 13, 2013 at 13:14 miko7358miko7358 4062 gold badges7 silver badges18 bronze badges 3
  • Hi can you get answer of this question. please i need this functionality. thank you – Renish Khunt Commented Apr 21, 2014 at 6:53
  • I accepted the following answer, just add your custom variable with a define – miko7358 Commented Apr 22, 2014 at 9:34
  • Just FYI these are more accurately "defined constants" and not "variables". – Jesse Nickles Commented Oct 13, 2020 at 10:07
Add a comment  | 

1 Answer 1

Reset to default 16

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;.

发布评论

评论列表(0)

  1. 暂无评论