The following code will print the uploads directory path in WordPress
$upload_dir = wp_upload_dir(); print $upload_dir['baseurl'];
It will return the path of WordPress upload directory such as http://yourdomain.com/wp-content/uploads
Basically, this function will print output like below
[path] => /var/www/html/wp-content/uploads/2018/06 [url] => https://yourdomain.com/wp-content/uploads/2018/06 [subdir] => /2018/06 [basedir] => /var/www/html/wp-content/uploads [baseurl] => https://yourdomain.com/wp-content/uploads [error] =>
You can write this as a function in your functions.php to retrieve the uploads directory path.
function tp_wordpress_uploads_directory_path() { $upload_dir = wp_upload_dir(); return $upload_dir['basedir']; }
Did this post help you?
Tutsplanet brings in-depth and easy tutorials to understand even for beginners. This takes a considerable amount of work. If this post helps you, please consider supporting us as a token of appreciation:
- Just want to thank us? Buy us a Coffee
- May be another day? Shop on Amazon using our links.
Your prices won't change but we get a small commission.
Leave a Reply