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!

3 thoughts on “How to Add a Site Name Shortcode to WordPress”

    1. Hey, Ace! If I understand it correctly, you’re wanting to have a shortcode that you can use to display a post or page’s title in the content?

      If that’s right, try this instead of the code above:

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

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

the Rick Beckman archive
Scroll to Top