Retrieve WordPress root directory path?

2020-01-26 06:01发布

How can I retrieve the path to the root directory in WordPress CMS?

标签: wordpress
12条回答
爷、活的狠高调
2楼-- · 2020-01-26 06:32

Try this function for get root directory path:

get_template_directory_uri();
查看更多
放我归山
3楼-- · 2020-01-26 06:38

You can use get_site_url() function to get the base url of the wordpress site.

For more information, please visit http://codex.wordpress.org/Function_Reference/get_site_url

查看更多
4楼-- · 2020-01-26 06:42

I think this would do the trick:

function get_wp_installation()
{
    $full_path = getcwd();
    $ar = explode("wp-", $full_path);
    return $ar[0];
}
查看更多
欢心
5楼-- · 2020-01-26 06:43

If you have WordPress bootstrap loaded you can use get_home_path() function to get path to the WordPress root directory.

查看更多
劳资没心,怎么记你
6楼-- · 2020-01-26 06:44

This an old question, but I have a new answer. This single line will return the path inside a template: :)

$wp_root_path = str_replace('/wp-content/themes', '', get_theme_root());
查看更多
ゆ 、 Hurt°
7楼-- · 2020-01-26 06:47

There are 2 answers for this question Url & directory. Either way, the elegant way would be to define two constants for later use.

define (ROOT_URL, get_site_url() );
define (ROOT_DIR, get_theme_root() );
查看更多
登录 后发表回答