//(let's say, if wordpress is installed in subdirectory: http://example.com/wpdir/)
home_url() 🡺 http://example.com/wpdir/ //if is_ssl() is true, then it will be "https"
get_stylesheet_directory_uri() 🡺 http://example.com/wpdir/wp-content/themes/THEME_NAME [same: get_bloginfo('template_url') ]
get_stylesheet_directory() 🡺 /home/user/public_html/wpdir/wp-content/themes/THEME_NAME
plugin_dir_url(__FILE__) 🡺 http://example.com/wpdir/wp-content/themes/PLUGIN_NAME
plugin_dir_path(__FILE__) 🡺 /home/user/public_html/wpdir/wp-content/plugins/PLUGIN_NAME/
FILE__
常量会给你当前文件的绝对路径。更新:
这个问题被改成了如何检索最初执行的脚本而不是当前运行的脚本。 唯一(??)可靠的方法是使用
debug_backtrace
函数来做到这一点。的例子。
https://(www.)example.com/subFolder/myfile.php?var=blabla#555
注意!。
DIRECTORY_SEPARATOR
对于Windows类型的主机返回``,而不是
/`。对于WordPress
如果你把它放在一个包含的文件中,它会打印出这个包含的路径。要获得父脚本的路径,用
$_SERVER['PHP_SELF']
代替__FILE__
。但要注意的是,PHP_SELF是一个安全风险!