ste*_*ase 120
查看wordpress根目录中wp-config.php文件的底部,可以找到如下内容:
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
有关示例文件,请查看此处:http:
//core.trac.wordpress.org/browser/trunk/wp-config-sample.php
你可以在wordpress脚本的其他地方使用这个名为ABSPATH的常量,在大多数情况下,它应该指向你的wordpress根目录.
Omr*_*dan 25
注意:这个答案非常陈旧,因此WordPress版本的内容可能已经发生了变化.
我猜您需要从插件或主题中检测WordPress根目录.我在FireStats中使用以下代码来检测安装FireStats的根WordPress目录以及WordPress插件.
function fs_get_wp_config_path()
{
$base = dirname(__FILE__);
$path = false;
if (@file_exists(dirname(dirname($base))."/wp-config.php"))
{
$path = dirname(dirname($base))."/wp-config.php";
}
else
if (@file_exists(dirname(dirname(dirname($base)))."/wp-config.php"))
{
$path = dirname(dirname(dirname($base)))."/wp-config.php";
}
else
$path = false;
if ($path != false)
{
$path = str_replace("\\", "/", $path);
}
return $path;
}
Run Code Online (Sandbox Code Playgroud)
下面是各种 WorPress 解决方案的获取目录。您可以根据需要选择任何人。
echo "<br/>".get_home_url(); // https://mysiteurl.com
echo "<br/>".ABSPATH; // /app/
echo "<br/>".get_home_path(); // /app/
echo "<br/>".get_site_url(); // https://mysiteurl.com
echo "<br/>".get_template_directory(); // /app/wp-content/themes/mytheme
echo "<br/>".dirname(__FILE__); // /app/wp-content/plugins/myplugin/includes
echo "<br/>".get_theme_root(); // /app/wp-content/themes
echo "<br/>".plugin_dir_path( __FILE__ ); // /app/wp-content/plugins/myplugin/includes/
echo "<br/>".getcwd(); // /app/wp-admin
Run Code Online (Sandbox Code Playgroud)
这是一个老问题,但我有一个新的答案.这一行将返回模板内的路径::)
$wp_root_path = str_replace('/wp-content/themes', '', get_theme_root());
Run Code Online (Sandbox Code Playgroud)
小智 6
这个问题Url&目录有2个答案.无论哪种方式,优雅的方法是定义两个常量供以后使用.
define (ROOT_URL, get_site_url() );
define (ROOT_DIR, get_theme_root() );
Run Code Online (Sandbox Code Playgroud)
Please try this for get the url of root file.
Run Code Online (Sandbox Code Playgroud)
第一种方式:
$path = get_home_path();
print "Path: ".$path;
// Return "Path: /var/www/htdocs/" or
// "Path: /var/www/htdocs/wordpress/" if it is subfolder
Run Code Online (Sandbox Code Playgroud)
第二种方式:
And you can also use
"ABSPATH"
this constant is define in wordpress config file.
Run Code Online (Sandbox Code Playgroud)
小智 5
主题根目录路径代码
<?php $root_path = get_home_path(); ?>
print "Path: ".$root_path;
Run Code Online (Sandbox Code Playgroud)
如果是子文件夹,则返回“路径:/var/www/htdocs/”或“路径:/var/www/htdocs/wordpress/”
主题根路径
$theme_root = get_theme_root();
echo $theme_root
Run Code Online (Sandbox Code Playgroud)
结果:- /home/user/public_html/wp-content/themes
| 归档时间: |
|
| 查看次数: |
140140 次 |
| 最近记录: |