Posted inwordpress

wordpress get uploads directory – wordpress get wp-content directory path

wordpress get uploads directory using $upload_dir = wp_upload_dir(); function. The path it returns will look something like:

wordpress get uploads directory | file upload to a folder in wordpress

Get Uploads Directory Path in WordPress source code – The following function can be used to get the absolute path to the WordPress uploads directory:

Get Uploads Directory Path In WordPress

The following bellow source code will print the uploads directory path in WordPress Example.

$resDir = wp_upload_dir();
print $resDir['baseurl'];

It will return the path of WordPress upload main base directory like as

[path] => /var/www/html/wp-content/uploads/2022/11
[url] =>
[subdir] => /2022/11
[basedir] => /var/www/html/wp-content/uploads
[baseurl] =>
[error] =>

You can bellow source code this as a function in your main functions.php to wordpress get uploads directory path.

function tp_wordpress_uploads_directory_path() {
	$resDir = wp_upload_dir();
	return $resDir['basedir'];

How to Change the Default Media Upload Location in WordPress?

Changing the Default Media Upload Location in WordPress

define( 'UPLOADS', 'wp-content/'.'files' );
define( 'UPLOADS', ''.'files' );

Get Uploads Directory Path in WordPress

In WordPress, you can get the uploads directory path using the wp_upload_dir() function. This function returns an array containing the directory path, URL, and other information related to the uploads directory.

To get the uploads directory path, you can use the following code:

$upload_dir = wp_upload_dir();
$upload_path = $upload_dir['basedir'];

The $upload_dir variable contains an array with the following keys:

path: the absolute server path to the uploads directory
url: the URL of the uploads directory
subdir: the subdirectory within the uploads directory where files are stored
basedir: the absolute server path to the base uploads directory (without the subdir part)
baseurl: the URL of the base uploads directory (without the subdir part)
error: any error message related to the uploads directory

In the code above, we’re getting the basedir key from the $upload_dir array to get the absolute server path to the uploads directory.

I hope you get an idea about wordpress get uploads directory.
I would like to have feedback on my
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype