How do I read values (PHP defined constants) from wp-config.php?

Steven picture Steven · Oct 27, 2011 · Viewed 24.9k times · Source

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?

Answer

ibex picture ibex · May 8, 2014

I have even defined my own constants in in wp-config.php and managed to retrieve them in theme without any includes.

wp-config.php

define('DEFAULT_ACCESS', 'employee');

functions.php

echo "DEFAULT_ACCESS :".DEFAULT_ACCESS;

outputs DEFAULT_ACCESS :employee