I have wordpress installed at:
http://example.com/wordpress/
When on homepage, the ABSPATH constant outputs exactly that, but when you navigate off to some other page, like:
http://example.com/wordpress/contact
the ABSPATH also turns to:
http://example.com/wordpress/contact
The question is, how can I obtain the actual root (marked in bold) no matter on which page I am - without hard-coding it?
I'm a bit confused with why ABSPATH changes value, aren't constants unchangeable once they are defined?
Thanks!
you can use Site_url();
... :)
I had the same issue on an admin page. Not only do you have to avoid the extra folder that gets inserted, WP may be installed in a folder itself.
Here is a way, albeit somewhat convoluted and written for clarity, that makes the adjustments for these various items. It does avoid DIRECTORY_SEPARATOR
issues as well:
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 . '"';
Shaken, not stirred, output:
Local WP path = '/wp/wordpress-3.4.2"
Of course, YMMV =;?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With