Basic example to produce the upload directory URL.
<?php $upload_dir = wp_upload_dir(); ?> <?php echo $upload_dir['baseurl']; ?>
More in-depth break down of the data returned.
<?php $uploads = wp_upload_dir(); // Array of key => value pairs /* $uploads now contains something like the following (if successful) Array ( [path] => C:pathtowordpress/wp-content/uploads/2010/05 [url] => http://example.com/wp-content/uploads/2010/05 [subdir] => /2010/05 [basedir] => C:pathtowordpress/wp-content/uploads [baseurl] => http://example.com/wp-content/uploads [error] => ) // Descriptions [path] - base directory and sub directory or full path to upload directory. [url] - base url and sub directory or absolute URL to upload directory. [subdir] - sub directory if uploads use year/month folders option is on. [basedir] - path without subdir. [baseurl] - URL path without subdir. [error] - set to false. */ echo $uploads['path'] . '<br />'; echo $uploads['url'] . '<br />'; echo $uploads['subdir'] . '<br />'; echo $uploads['basedir'] . '<br />'; echo $uploads['baseurl'] . '<br />'; echo $uploads['error'] . '<br />'; $upload_dir = ( $uploads['url'] ); $upload_dir_alt = ( $uploads['baseurl'] . $uploads['subdir'] ); // Now echo the final result echo $upload_dir . '<br />'; // Output - http://example.com/wp-content/uploads/2010/05 // Using year and month based folders, the below will be the same as the line above. echo $upload_dir_alt . '<br />'; // Output - http://example.com/wp-content/uploads/2010/05 ?>
Revisions
There are no revisions for this post.
No comments yet.