How to get wp upload path

Last Updated:December 7, 2023

If you want to get the upload path of the WordPress in your custom coding you can use the following code.

$upload_dir = wp_upload_dir();

// Your folder name
$folder_name = 'icons';

// Path to the folder
$folder_path = $upload_dir['basedir'] . '/' . $folder_name;

// Check if the folder exists
if (file_exists($folder_path)) {
    // Now you can access files within the folder
    echo "Folder exists at: $folder_path";
} else {
    echo "Folder not found";