How can I retrieve the path to the root directory in WordPress CMS?
相关问题
- Display product ACF field value in Woocommerce tra
- Adding a custom button after add to cart button in
- How to add a “active” class to a carousel first el
- Setting custom order statuses as valid for payment
- change the font size in tag cloud
相关文章
- wordpress新增页面如何个性化设置
- select query in wordpress
- Get WooCommerce featured products in a WP_Query
- Woocommerce update shipping methods in checkout vi
- Change order status just after payment in WooComme
- Publishing or uploading failed. Error message: “Th
- Facebook Login With WP JWT Auth
- Wordpress development process
Note: This answer is really old and things may have changed in WordPress land since.
I am guessing that you need to detect the WordPress root from your plugin or theme. I use the following code in FireStats to detect the root WordPress directory where FireStats is installed a a WordPress plugin.
Looking at the bottom of your wp-config.php file in the wordpress root directory will let you find something like this:
For an example file have a look here:
http://core.trac.wordpress.org/browser/trunk/wp-config-sample.php
You can make use of this constant called ABSPATH in other places of your wordpress scripts and in most cases it should point to your wordpress root directory.
First Way:
Second Way:
echo
ABSPATH;
// This shows the absolute path of WordPressABSPATH
is a constant defined in the wp-config.php file.For retrieving the path you can use a function
<?php $path = get_home_path(); ?>
. I do not want to just repeat what had been already said here, but I want to add one more thing:If you are using windows server, which is rare case for WordPress installation, but still happens sometimes, you might face a problem with the path output. It might miss a "\" somewhere and you will get an error if you will be using such a path. So when outputting make sure to sanitize the path: