Using Images in WordPress – Best Practices

I guess from the question you are asking, is there a way to code the image url that is better than typing in the whole url? This is what I do, to ensure that if the domain name ever changes…(which they do in my work because I always build the sites on a project domain and then move them over), you will want to do it this way:

<img src="https://wordpress.stackexchange.com/questions/62714/<?php echo get_bloginfo("template_url'); ?>/images/image-name.jpg alt="whatever" />

You can also use this (and yes I know it is not the technically correct way to call css) when using css in a template:

<style>
#div {
     background-image: url(<?php echo get_bloginfo('template_url'); ?>/images/image-name.jpg);
}
</style>

It works for inline css as well:

<h2 style="background-image: url(<?php echo get_bloginfo('template_url'); ?>/images/image-name.jpg);">Some Title</h2>

I think this is what you were asking…

Leave a Comment