Bloginfo Shortcode

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 ) {
       '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" />


  1. User Avatar
    Jermaine Oppong
    Permalink to comment#

    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" />

    • User Avatar
      Insight Studios
      Permalink to comment#

      Well this will help the tags for using it in post editor.

    • User Avatar
      Permalink to comment#

      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.

  2. User Avatar
    Permalink to comment#

    Awesome! Just what i was looking for, thanks!

  3. User Avatar
    Insight Studios
    Permalink to comment#

    Thanks for this :) Using it it my functions.php file with credits to this page :)

  4. User Avatar

    Ohhh thanks !!! That what i needed !!! Thanks a lot !

  5. User Avatar
    Agi ogaga
    Permalink to comment#

    Nice… pls Chris dont stop being awesome…

  6. User Avatar
    Chris Not-Coyier
    Permalink to comment#

    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.

  7. User Avatar
    Permalink to comment#

    superb that function work for me very good shortcode for wordpress h using template path in wordpress

  8. User Avatar

    Thx a lot, but i changed to manage 2 parameters of get_bloginfo function, it’s better like this.

    function deazweb_bloginfo_shortcode( $atts ) {
           'key' => '',
           'filter' => '',
       ), $atts));
       return get_bloginfo($key, $filter);

Leave a Comment

Posting Code!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.