There are many instances when you may want to implement a custom shortcode in WordPress – be it a time saving exercise for yourself or for a client. There are many ways to create shortcodes for the more advanced wordpress developer or user, however if you are looking for a simple fix to save you a second or two, then this is it!

Here is the code :

Place this in your functions.php file, right at the bottom.

function page_footer_shortcode() {  $include = include 'includes/content-footer.php'; return $include; } add_shortcode('get-in-touch','page_footer_shortcode');

What does that mean?

This is simply saying that I want to add a shortcode, which I will include in a folder in my theme. Then, when someone enters “[get-in-touch]” in the WordPress editor in the back-end, when published, it gets replaced with the content you specified in the file you created. Simple! I have a file inside my theme folder called “content-footer.php”, which is within a folder called “includes”. The code inside that file is as follows:

 <?php $html = " <div class="get-in-touch"> <ul> <li> GET IN TOUCH : </li> <li class="phone-get-in-touch"> 214.208.3830 </li> <li class="email-get-in-touch"> [email protected] </li> </ul> </div> "; return $html; ?>

What does that mean?

This is really simple PHP code. It declares a variable, which is called ‘html’ and inside that (not by chance) is the html you will be putting into your post or page if you decide to use shortcodes inside a theme file. The only thing to watch out for in the html code is that you have to put a before your speech marks. That variable is then returned to wherever it is needed. Hopefully that wasn’t too complicated. This can be a real time saver if you want to give a client the ability to add a couple of different content options at the bottom of their website pages or blog posts.

Subscribe to our newsletter!

Get the latest tips and advice through the Authentic Style newsletter

Please enable JavaScript in your browser to complete this form.

by subscribing you’ll receive periodic emails from us with helpful website tips.

Let’s create something
great together.

All great things start with a chat. Use the adjacent form or our project planner to get things started.

Project Planner

We’re currently accepting projects
Please enable JavaScript in your browser to complete this form.

Authentic Insights