Update:

I’ve been meaning to update this for ages, the old method was more a proof of concept and rather pointless as it would be overwritten by an update to the WordPress core. A better way to go about getting the image directory in your templates would be as follows:

echo get_bloginfo('template_directory') . '/images/abc.png';
echo get_bloginfo('template_directory') . '/images/def.png';

This will output http://yoursite.com/wp-content/themes/your-theme/images/abc.png assuming ‘images’ is the name of the folder you have your images in. A further slight improvement would be to save the image directory in a variable in your template file to save on a bit of code and a marginal performance improvement of not calling a function multiple times.

$image_directory = get_bloginfo('template_directory') . '/images/';

echo $image_directory . 'abc.png';
echo $image_directory . 'def.png';

Old Solution:

The aim of this post is to edit the get_bloginfo function so that it will output the directory of the image folder of your current WordPress theme.

To start off you need to find your WordPress folder and go into the wp-includes directory. From there locate the general-template.php file and open it up in your chosen text/code editor. It’s a rather large file so I’d suggest running a find search for the following text: function get_bloginfo. Or you can search for it yourself, it’s on line 400.

From there scroll down until you find the line with case ‘template_url’: on it. Two lines below this you should see the break; statement and below this is where we are going to add in our code. Copy and paste the code below into a gap underneath the break; statement.


case 'img_directory' :
$output = get_template_directory_uri() . "/images/";
break;

You can now use the code as shown below:


echo bloginfo('img_directory');