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:

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

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

Test the page

Viola!

Leave a Reply

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