I’ve gathered that I upload the images to wp-content/uploads
, but once there, how do I link to it in my template files?
If I created a new template after putting, say, dog.jpg
in that uploads directory, <img src="dog.jpg" />
does not work – the image doesn’t display.
I read <?php bloginfo('template_directory'); ?>
should be inserted (I guess?), but putting it before dog.jpg
in the src
does not help.
Try to give full path to the image (with ‘http://’ and the host), e.g. ‘http://myblog.com/wp-content/uploads/dog.jpg’. Or may be give a relative path: “wp-content/uploads/dog.jpg”.
Also, as far as I remember, wordpress’ upload function puts the images in some subdirectories of wp-content/uploads based on the date when you have uploaded the image.
If you are uploading images to the wp-content/uploads directory you should be using the media uploader in the wordpress backend. Then the file URL is automatically set and given to you for each image. If you don’t want to use the media uploader in wordpress you should be using an image directory in the theme folder, then target those images with:
<img src="<?php echo get_template_directory_uri(); ?>/images/dog.jpg" />
Try this and it will work.
If the image is for a template in your theme, you should be storing the image along with your theme files. The media uploader is more for your content authors to work with.
If you still desire to reduce repetition (maybe you need to use the image in your content too), then you could hardcode a link to the image as it exists in the uploads folder. But do you really want to risk having a content author delete it and thus break your theme?