How to get path to the wp_content directory in WordPress plugin


You are writing a wordpress plugin in which you need the path to the wp-content directory on the filesystem.


Use the WP_CONTENT_DIR constant.

$path_to_wp_content = WP_CONTENT_DIR; // e.g. "/var/sites/"

Note that WP_CONTENT_DIR has no trailing slash.

Use WP_CONTENT_DIR . "/" like this

$path_to_wp_content = WP_CONTENT_DIR . "/"; // e.g. "/var/sites/"

to get the path to wp_content including a trailing slash.