How do I read values from wp-config.php?

2019-03-25 02:59发布

I need to get username, password etc from the wp-config file to connect to a custom PDO database.

Currently I have another file where I have this info, but I would like to only use the wp-config.

So how can I read the different properties of wp-config?

标签: wordpress
7条回答
我只想做你的唯一
2楼-- · 2019-03-25 04:05

I would just include the file then I would have access to the variable in it varibales.

<?php
  require_once('wp-config.php');
  echo DB_NAME;
?>

This is assuming you're on the same server and you can access wp-config.php through the file system.

If you're doing this for a plugin, these values are already available. You won't need to include the file again.

查看更多
登录 后发表回答