I am using Bones theme to develop wordpress themes. Images are stored in ‘theme/lib/images/site/’. To load an image in a template I a currently using:
<?php get_template_directory_uri().'/library/images/'; ?>
I would like to add this directory as a global variable in functions.php so I can use a shortcode to load images, for example.
<?php echo imgDir(); ?>
My first thought would be to use something like
function imgDir() {
$path_to_image = get_template_directory_uri() . '/library/images/';
}
But does not seem to be working, am I missing something simple here? Shouldn’t be to hard to add a short code like this.
You need to return your value:
The proper way to add a shortcode hook according to the WordPress Documentation is this.
Inside your functions.php
So the shortcode
[imgdir]
will return the desired path.To call a shortcode inside your PHP-File just use the
do_shortcode()
function like this –echo do_shortcode('[imgdir]');
(Documentation)