Bloginfo Shortcode

Last updated on:

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

Reference URL


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

    • Insight Studios
      Permalink to comment#

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

    • augsteyer
      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. Justin
    Permalink to comment#

    Awesome! Just what i was looking for, thanks!

  3. Insight Studios
    Permalink to comment#

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

  4. Mrfou

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

  5. Agi ogaga
    Permalink to comment#

    Nice… pls Chris dont stop being awesome…

  6. 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. Adil
    Permalink to comment#

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

  8. alphonix

    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

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

  function example() {
    element.innerHTML = "<div>code</div>";

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed