Grow your CSS skills. Land your dream job.

Last updated on:

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

Reference URL

Comments

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

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

    Awesome! Just what i was looking for, thanks!

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

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

  5. Nice… pls Chris dont stop being awesome…

  6. 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

Leave a Comment

Posting Code

Markdown is supported in the comment area, so you can write inline code in backticks like `this` or multiline blocks of code in in triple backtick fences like this:

```
<div>Example code</div>
```

You don't need to escape code in backticks, Markdown does that for you. If anything screws up, contact us and we can fix it up for you.

*May or may not contain any actual "CSS" or "Tricks".