close-up image of a woman wearing a hoodie and glasses with bright lights reflected in the lenses

How to Add a Site Name Shortcode to WordPress

A cosmic cloud of gases condenses under its own gravity, forming a star. Generations upon generations of single-celled organisms lead to multi-cellular complex life. And your humble blog has grown beyond its seminal inspiration.

Change happens, and you don’t have to find yourself in a situation where if you decide to change the name of your site, you’ll need to find and replace potentially hundreds of mentions of the old name to keep your branding consistent.

Most of my online projects suffer from many identity crises as I refine over and over again what it is I want to do with my online presence. To save myself all of the trouble of laboriously updating references to my site’s title throughout all of a its content, I started using an incredibly simple WordPress shortcode to do the work for me.

Installation

There are multiple ways in which you can add this shortcode to your WordPress installation, among them:

  • Add the following code block to your theme’s functions.php file.
  • If you’re using Thesis 1.8.5, add the following code block to your theme’s custom_functions.php file.
  • If you’re using a custom plugin to hold your site’s customizations, add the code block to it.
  • Last, you can ignore the code block altogether by downloading this code block as a WordPress plugin, which can then be uploaded via your site admin panel’s Plugins → Add New page.

The Code

/**
 * [sitename] — Site name shortcode
 *
 * @via https://www.rickbeckman.org/log/sitename-shortcode/
 */
add_shortcode( 'sitename', function() { return get_bloginfo(); } );

Usage

Once installed, you can insert your site name into your content by using [sitename] anywhere where shortcodes are processed, such as in any of your posts or pages.

Now, no matter how many times you update your site’s title in Settings -> General, you can be assured that your content will always refer to its current name!

If this shortcode was useful to you, you might also appreciate one of my other WordPress tweaks, and of course, don’t forget to like this page and share it with your fellow WordPress’ers!

This post was originally published on 2013-04-06. It has been updated for republication. Comments below may reflect the original version of this content.

One thought on “How to Add a Site Name Shortcode to WordPress

Join the Discussion

Your email address will not be published. Required fields are marked *

Comments must be made in accordance with the comment policy. Use your Gravatar-enabled email address while commenting to automatically enhance your comment with some of Gravatar's open profile data.

You may use Markdown to format your comments; additionally, these HTML tags and attributes may be used: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>