Recuperar ruta del directorio raíz de WordPress?
¿Cómo puedo recuperar la ruta al directorio raíz en WordPress CMS?
12 answers
Supongo que necesitas detectar la raíz de WordPress de tu plugin o tema. Utilizo el siguiente código en FireStats para detectar el directorio raíz de WordPress donde FireStats está instalado un plugin de 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;
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-08 18:44:29
Mirando la parte inferior de tu wp-config.el archivo php en el directorio raíz de wordpress le permitirá encontrar algo como esto:
if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/');
Para un archivo de ejemplo, eche un vistazo aquí:
http://core.trac.wordpress.org/browser/trunk/wp-config-sample.php
Puede hacer uso de esta constante llamada ABSPATH en otros lugares de sus scripts de wordpress y en la mayoría de los casos debe apuntar a su directorio raíz de wordpress.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-03-01 14:34:41
Echo ABSPATH;
/ / Esto muestra la ruta absoluta de WordPress
ABSPATH
es una constante definida en wp-config.archivo php.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-28 06:47:16
Esta es una vieja pregunta, pero tengo una nueva respuesta. Esta sola línea devolverá la ruta dentro de una plantilla::)
$wp_root_path = str_replace('/wp-content/themes', '', get_theme_root());
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-07-26 05:45:15
Please try this for get the url of root file.
Primera manera:
$path = get_home_path();
print "Path: ".$path;
// Return "Path: /var/www/htdocs/" or
// "Path: /var/www/htdocs/wordpress/" if it is subfolder
Segunda manera:
And you can also use
"ABSPATH"
this constant is define in wordpress config file.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-07-08 10:49:56
Hay 2 respuestas para esta pregunta Url y directorio. De cualquier manera, la forma elegante sería definir dos constantes para su uso posterior.
define (ROOT_URL, get_site_url() );
define (ROOT_DIR, get_theme_root() );
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-21 06:37:52
Creo que esto haría el truco:
function get_wp_installation()
{
$full_path = getcwd();
$ar = explode("wp-", $full_path);
return $ar[0];
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-28 02:47:13
Para recuperar la ruta puede usar una función <?php $path = get_home_path(); ?>
. No quiero simplemente repetir lo que ya se había dicho aquí, pero quiero añadir una cosa más:
Si está utilizando Windows Server, que es un caso raro para la instalación de WordPress, pero todavía sucede a veces, es posible que se enfrente a un problema con la salida de la ruta. Es posible que se pierda un " \ " en algún lugar y obtendrá un error si va a utilizar una ruta de este tipo. Así que al salir asegúrese de desinfectar la ruta:
<?php
$path = get_home_path();
$path = wp_normalize_path ($path);
// now $path is ready to be used :)
?>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-05-04 08:16:53
Pruebe esta función para obtener la ruta del directorio raíz:
get_template_directory_uri();
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-12 04:46:21
Puedes usar la función get_site_url() para obtener la url base del sitio de wordpress.
Para obtener más información, visite http://codex.wordpress.org/Function_Reference/get_site_url
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-04 15:48:32
Si tiene WordPress bootstrap cargado puede utilizar get_home_path()
función para obtener la ruta al directorio raíz de WordPress.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-21 06:15:40
Código de ruta del directorio raíz del tema
<?php $root_path = get_home_path(); ?>
print "Path: ".$root_path;
Devuelve "Path: / var/ www / htdocs /" o " Path: /var/www/htdocs/wordpress/" si es subcarpeta
Ruta raíz del tema
$theme_root = get_theme_root();
echo $theme_root
Resultados:-/home/user/public_html/wp-content / themes
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-14 05:45:02