Information Technology Grimoire

Version .0.0.1

IT Notes from various projects because I forget, and hopefully they help you too.

WordPress Custom Template Short Code

If you have ever tried to configure a custom template but wanted to add a short code, then you probably used something like this….

I wanted the 404 page on Ruby Sash to list a dynamic sitemap in case someone was looking for a page that we removed or moved. However, the 404 template didn’t have this ability. The sitemap plugin I have though, lists all of the posts by category.

We wanted to modify our template to use a short code directly instead of within the normal content of a post or page. WordPress uses a function called “do_shortcode” that seemed to do the trick. Here is how we added a short code to our custom template in WordPress.

Backup your Theme File

If you are using a shell you would type:

cd /var/www/
cp somefile.php somefile.php.backup

Edit the Theme File

Using your normal file editing method (ssh and vim for me), open the wp-content/theme/somefile.php and add the following code:

do_shortcode Function in WordPress

<?php echo do_shortcode("[simple-sitemap-group]"); ?>

You would replace [simple-sitemap-group] with whatever your short code is of course.

Test the page


Last updated on 1 Mar 2019
Published on 1 Mar 2019