Ebuka Val
  • Blogging
    • Affiliate Marketing
    • Artificial Intelligence
    • Blogging and Niche Websites
    • Monetization
    • WordPress
  • E-Commerce
    • Amazon FBA
    • Dropshipping
  • Make Money
    • Make Money Online
    • Self Publishing
    • Sidehustles
    • Start A Business
  • Social Media
    • Facebook
    • Instagram
    • Pinterest
    • TikTok
    • YouTube
  • Free ToolsNew
    • YouTube Tools
      • YouTube Title Generator
      • YouTube Tag Extractor
      • YouTube Tag Generator
      • YouTube Description Generator
      • YouTube Earnings Calculator
    • Website Management Tools
      • AdSense Revenue Calculator
      • Keyword Suggestion Tool
      • Robots.TXT Generator
      • Meta Tag Generator
      • Hosting Checker
      • WordPress Theme Detector
    • Text Analysis
      • Article Rewriter
      • URL Rewriter
Notification Show More
Latest News
adnow vs adsense
NEW! AdNow vs AdSense: Detailed Comparison for Publishers
Monetization
Best About Us Page Generators
9 Of the Best About Us Page Generators using AI (2023 Review)
Artificial Intelligence
How to Install WordPress Using CPanel
How to Install WordPress Using cPanel with & without Softaculous (2023 Guide)
WordPress
Tips to Secure and protect Your WordPress Website
10 Tips to Secure and Protect your WordPress Website in 2023
WordPress
How Much Time Do YouTubers Spend Editing?
How Much Time Do YouTubers Spend Editing?
YouTube
Aa
Aa
Ebuka Val
Search
  • Blogging
    • Affiliate Marketing
    • Artificial Intelligence
    • Blogging and Niche Websites
    • Monetization
    • WordPress
  • E-Commerce
    • Amazon FBA
    • Dropshipping
  • Make Money
    • Make Money Online
    • Self Publishing
    • Sidehustles
    • Start A Business
  • Social Media
    • Facebook
    • Instagram
    • Pinterest
    • TikTok
    • YouTube
  • Free ToolsNew
    • YouTube Tools
    • Website Management Tools
    • Text Analysis
Have an existing account? Sign In
  • About Us
  • Blog
  • Contact Us
  • Terms & Conditions
Learn From a Bunch of Tutorials available for Free.
We may receive a commission for purchases made through links in this post. However, this does not impact our reviews and comparisons.
WordPress

How to Create Shortcode in WordPress (Fast and Easily)

This WordPress shortcode tutorial demonstrates all the steps to create a shortcode in your WordPress website. –

Ebuka Val
Last updated: 2022/09/12 at 2:06 PM
Ebuka Val Published September 12, 2022
Share
6 Min Read
How to Create Shortcode in WordPress
How to Create Shortcode in WordPress
SHARE
Article Summary
  • All the necessary code snippets that you need are available in the article below as text or as image.
  • Do note that the process of creating shortcodes in wordpress requires some coding knowledge.
  • This article helps you create a WordPress Shortcode in only a few minutes, it's the fastest tutorial of it's kind.

In this article, we’re going to learn how to create Shortcode in WordPress. 

A WordPress Shortcode is simply a small piece of PHP code that allows you to quickly add elements to your WordPress Website’s page and post. 

In other words, shortcodes save you time when customizing your website so you wouldn’t need additional plugins for that. 

WordPress provides 6 default shortcodes which are:

  • [ audio ] – used to play audio files. 
  • [ playlist ] – display a collection of audio and video files. 
  • [ gallery ] – for showing image gallery. 
  • [ video ] – used to embed and play video files. 
  • [ embed ] – encloses embedded items. 
  • [ caption ] – wraps caption around your content. 

Do note that there are no spaces in between the word and the square brackets ( [shortcode] ), I only added them so this article wouldn’t display my WordPress Files.

Ebuka Val

But with some coding knowledge, you can also create your own custom WordPress Shortcode.

For example, if you use a Call to Action button such as ‘Subscribe’ on every post, having a dedicated Shortcode ready will help you publish your articles faster and more efficiently. 

We will create a custom Shortcode to add Social Media links as an example but before we start, I do recommend Backing up your WordPress Website.

Create a New Theme File 

The first step we’ll take is to create a new theme file using the FTP client, note that you can also do this using the cPanel for your hosting company. 

Recommend Hosting: If you want to host your website without issues and easily create shortcodes, you should host your site on Bluehost. 

Once FTP Connection is set, navigate to WP Content and then click on Themes. You should open your current theme’s directory and in the theme directory, create a new file and name it ‘myshortcodes.php’. 

Open the myshortcodes.php file, do this by right-clicking on the file and clicking on view/edit, this will then open the file with a text editor. 

Once the file is open add the block code below and save the file, you may need to confirm changes in some hosting servers like Hostinger. 

<?php

?> 

Edit Functions.php

The next step is to open the functions.php file right in the same theme’s directory (your active theme) and add the code below at the bottom of the document: 

include ( 'myshortcodes.php' )

After adding the code to your functions.php file, click on Save Changes and proceed to the next step which is…

Create a Shortcode Function 

The next step we need to take now is to create a shortcode function, all you have to do is open the myshortcodes.php file again by right-clicking and then selecting view/edit. 

You should now insert your desired action (function), then add a callback function under the previous function so that WordPress will know that the action is a shortcode. 

The myshortcodes.php file should look like the image below…

Your new shortcode file will look like this After adding the function and callback code
Your new shortcode file will look like this After adding the function and callback code

Save the myshortcodes.php file and your custom Shortcode is ready, the next step is to…

Test your Shortcode 

To test your Shortcode, you only need to create a new post or page on your WordPress Website and add the Shortcode [Subscribe].

Once you Preview the post, you should see your Shortcode working. 

How the shortcode works on the frontent of my test site
How the shortcode works on the frontent of my test site

You can add more custom parameters to your Shortcode by editing the file later. 

Enclosing Shortcodes

So far so good, I taught you how to create a self-closing Shortcode, self-closing shortcodes are a sort of standalone shortcodes that don’t need a closing tag. 

For example, , ,

image 55 Ebuka Val
image 56 Ebuka Val
image 57 Ebuka Val
How to Create Shortcode in WordPress
How to Create Shortcode in WordPress
, and are all self-closing shortcodes. Enclosing shortcodes have a start and end tag allowing you to wrap around content.

and are examples of enclosing shortcodes. Let’s now learn how to create custom enclosing shortcodes in WordPress. 

Creating an Enclosing Shortcode 

Go back to your Active Theme’s directory and open the myshortcodes.php file and then you should add new lines of code, the final lines should look like the ones in the image below.

image 57 Ebuka Val
Creating an enclosing shortcode in wordpress

The Next step is just to preview your Shortcode by simply adding it to a WordPress Post or Page. 

Final Thoughts 

So now you know how to create your own custom WordPress Shortcode, and as you know, it’s incredibly fast. 

Want a more visual tutorial on How to create a shortcode in WordPress, Watch This.

If you have any questions regarding WordPress Shortcodes, do not hesitate to ask me in the comments. 

Share this Article
Facebook Twitter Pinterest Reddit
Posted by Ebuka Val
Follow:
Hello! My name is Ebuka Val and I am a freelance SEO expert and writer. With years of experience in the industry, I have honed my skills in helping websites rank higher on search engines through effective search engine optimization techniques. In addition to my SEO work, I am also a writer and have written extensively on various topics related to blogging, affiliate marketing, and making money online. My passion for these topics has led me to create my own website, ebukaval.com, where I share my insights and strategies with my readers. I am constantly learning and expanding my knowledge in the digital marketing space, and I am always on the lookout for new opportunities to help businesses and individuals achieve their online goals. When I'm not working, I enjoy spending time with my family and exploring new hobbies. Thank you for taking the time to read about me, and feel free to contact me if you have any questions or would like to collaborate on a project.
Leave a review

Leave a review Cancel reply

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

Please select a rating!

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

Subscribe to Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

You Might Also Like

How to Install WordPress Using CPanel

How to Install WordPress Using cPanel with & without Softaculous (2023 Guide)

January 16, 2023
Tips to Secure and protect Your WordPress Website

10 Tips to Secure and Protect your WordPress Website in 2023

January 16, 2023
How to Upload and Install WordPress Plugins

How to Upload & Install a WordPress Plugin for Beginners

January 5, 2023
How to Insert Tables In WordPress Easily

How to Insert a Table in WordPress without Plugins

January 5, 2023
Newsletter Subscription

Subscribe to our newsletter to get our newest articles instantly!

Ebuka Val
Follow US

© 2023 www.ebukaval.com - All Rights Reserved.

  • About Us
  • Blog
  • Contact Us
  • Terms & Conditions
mailchimp email
Join Us!

Subscribe to our newsletter and be the first to know about the latest tips, tricks, and trends in blogging, affiliate marketing, artificial intelligence, YouTube, and making money online. And also get Free Guides!

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?