Apr 21, 2017

Get Uploads Directory Path in WordPress

The following function can be used to get the absolute path to the WordPress uploads directory:

/**
 * Get the absolute path to the WordPress uploads directory,
 * with a trailing slash.
 *
 * @return string The uploads directory path.
 */
function km_get_wordpress_uploads_directory_path() {
	$upload_dir = wp_upload_dir();

	return trailingslashit( $upload_dir['basedir'] );
}

It will return a path to where the WordPress /uploads/ directory is, whether it’s in the default location or whether an UPLOADS constant has been defined to specify an alternate location. The path it returns will look something like:

/path/to/wordpress/wp-content/uploads/