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

<?php 
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'); 
?>

Usage

[shortcode_name]

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