How obatain wordpress root url (ABSPATH changes on every page)

I have wordpress installed at:

http://example.com/wordpress/

When the constant ABSPATH displays exactly this on the home page, but when you go to another page, for example:

http://example.com/wordpress/contact

ABSPATH also refers to:

http://example.com/wordpress/contact

The question is, how can I get the actual root (in bold) no matter what page I am on - without hard coding it?

I'm a little confused about why ABSPATH changes the value, aren't constants immutable after they are defined?

Thank!

+5
source share
4 answers

you can use Site_url();... :)

+2

. , WP .

, , . DIRECTORY_SEPARATOR:

if (!defined(PLUGINUPDATEMGR_DOMAIN)) 
    define("PLUGINUPDATEMGR_DOMAIN", strtolower( $_SERVER['HTTP_HOST'] ) );

$wprootbase = strtolower( site_url() );

$wprootstart = strpos( $wprootbase, PLUGINUPDATEMGR_DOMAIN ) + 
    strlen( PLUGINUPDATEMGR_DOMAIN  ); // + 1 to strip the leading slash/backslash

$wprootend = strlen( $wprootbase );

$wproot = substr( $wprootbase, $wprootstart, $wprootend );

echo "Local WP path = '" . $wproot . '"';

, , :

Local WP path = '/wp/wordpress-3.4.2" 

, YMMV =;?)

+4

ABSPATH php , /var/www/wordpress/, Wordpress.

:

site_url()

bloginfo()

, .

$var = get_bloginfo ('wpurl');

0

<?php echo esc_url( home_url( '/' ) ); ?>

, 30

0

All Articles