Creating a Simple WordPress Shortcode

/Creating a Simple WordPress Shortcode

WordPress is the most popular content management system, and one of the foundations of its success is its shortcode system. And while you may think this is best left to a website programmer, writing a WordPress shortcode is actually much easier than you think.

The following shortcode example will show you how to display a sample of random text via a shortcode which can be added to any post or page. Simply replace the text content to your own, rename the shortcode to make it your own and you’re good to go.

The code itself should be added to your theme’s functions.php file, which you can find in /wp-content/themes/your-theme/. If you don’t see a functions.php file there, you can simply create one and put the code in it, making sure you start the start and end the file with the PHP tags if necessary.

Simple Shortcode Example

function my_shortcode() {
    return 'I am a shortcode.  This text will display when I add the custom shortcode to my content.';
add_shortcode('shortcode_name', 'my_shortcode'); 



And that’s all you’ll need to get started. Creating a WordPress shortcode is actually easier than you think.

2018-11-09T16:58:11+00:00November 9th, 2018|WordPress|0 Comments

About the Author:

Warren Chandler is a freelance web programmer and web developer, based in Frinton on Sea, Essex. Warren specialises in web programming, web design, corporate identity, copy writing, SEO, logo and print media for home, work, and mobile platforms.

Leave A Comment

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