The bloginfo() function in WordPress gives you access to lots of useful information about your site. See the complete list. To access all these values from inside Page/Post content itself, we can make a shortcode to return the values. Add this to your functions.php file in your theme:
function digwp_bloginfo_shortcode( $atts ) {
extract(shortcode_atts(array(
'key' => '',
), $atts));
return get_bloginfo($key);
}
add_shortcode('bloginfo', 'digwp_bloginfo_shortcode');
Now you can output any of the values by calling that shortcode with “key”. For example, the name of your site:
[bloginfo key='name']
Or directly to images in your theme folder:
<img src="[bloginfo key='template_url']/images/logo.jpg" alt="[bloginfo key='name'] logo" />
I thinking the embed line you suggested would not work in template files without using the do_shortcode() function:
<img src="<?php do_shortcode('[bloginfo key='template_url']'); ?>/images/logo.jpg" alt="<?php do_shortcode('[bloginfo key='name']'); ?> logo" />
Well this will help the tags for using it in post editor.
You would need the do_shortcode() if you are using it in the .php files that is true. However, why would you want to use the shorcode in php files if you already can do the bloginfo(‘url’); . The shortcode is for posts/pages use.
Awesome! Just what i was looking for, thanks!
Thanks for this :) Using it it my functions.php file with credits to this page :)
Ohhh thanks !!! That what i needed !!! Thanks a lot !
Nice… pls Chris dont stop being awesome…
THANK. YOU. I spent the last two and a half hours trying to figure out how to get relative image paths working from within a WordPress page, and was about to settle for using the WordPress image uploader. Now I can still work in code, thank God. Credited within my functions.php page.
superb that function work for me very good shortcode for wordpress h using template path in wordpress
Thx a lot, but i changed to manage 2 parameters of get_bloginfo function, it’s better like this.