Support » Fixing WordPress » any way to use bloginfo() to link to uploads directory?

  • I am curious if there is anyway to use bloginfo() to link to the uploads directory… rather than write an absolute url either from the domain level ( or the server root level (/wp-content/uploads/)

    Ideas or perhaps there’s some other function I could use to generate the correct path to my uploads (or custom uploads) directory?

    If not, there SHOULD be, imo. I’d like to see some sort of function that read the database and tap into the value you put in the misc. settings for your uploads path.

    If there IS something like this, please let me know…

Viewing 7 replies - 1 through 7 (of 7 total)
  • So… if I echo’d

    <img src=”<?php echo get_option(‘upload_path’); ?>/image.jpg” />

    (assuming I am not using year, month, etc), that would return an absolute url to the uploads directory location indicated in the misc settings?

    Is that function understood by default by WordPress or something I have to add to a functions.php file? Or explicitly include somewhere?

    and… do I assume that this is associated with a post and therefore must be within the loop?

    What is it exactly that you’re attempting to do?..

    If you want to print out images from your uploads directory from files uploaded via the media library there are attachment functions for the job.

    No, I simply want to “get” (as in dynamically write it) the path to the uploads (or custom folder) where the media uploader puts files.

    For example, if one isn’t a developer using something that includes an FTP program, one might edit templates and want to include a file that the site owner or editor would upload… if I were putting that file up with FTP in my own program, I’d likely include it in a folder in my theme and could write that as:

    <?php bloginfo(‘template_directory’); ?>/myimages/ and then tap into a custom field entry to generate the file name from the db… but the uploads is outside of the theme folder… and can be something OTHER than uploads

    I want to know how to dynamically generate a path to the uploads (or custom location) outside of the template_directory rather than write /wp-content/uploads/ (hard coding it)

    Surely this is possible?

    Here is an actual practical example of how to use what this vague page is talking about:

    Not sure if this is best practice or whatever but it worked for me.

    First, I had to define a variable with the wp_upload_dir function. Calling the wp_upload_dir function gives you the ability to call a bunch of different variations of paths to the uploads directory.

    $image_path = wp_upload_dir();

    This is where that link didn’t help because I am really a php modifier not a php programmer. I ended finding out that all this stuff:

        [path] => /home/
        [url] =>
        [subdir] => /2008/11
        [basedir] => /home/
        [baseurl] =>
        [error] =>

    meant that you have to take your variable with the wp_upload_dir and add an array that looks something like this:


    this will now make this dynamically pull the upload url for whatever post you are dealing with:

    <img src="<?php echo $image_path['url']; ?>/image.jpg" />

    Hope this helps more than a link reference.

    @blockbot, thanks, you did explain it better. As is often the case the WP Codex assumes you are an experienced PHP user, whereas some of us need a little more help.

    @t31os_, yes your post was useful, but, as blackbot said, for some of us the Codex page was “a little vague”. Perhaps you were a little arrogant to suggest that a link to one solution is an explicit answer to the posters problem.

    Fine by me, i do have off days where i bite, i’ve retracted my response, i’ll admit i was a little arrogant.

    I’ll do something a little more useful with myself, i’ll rewrite that page so it’s clearer.. 🙂

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘any way to use bloginfo() to link to uploads directory?’ is closed to new replies.