Shortcode in WordPress

Home » Blog » Shortcode in WordPress

Have you ever wanted to make a shortcode in WordPress? I will show you how to make it without plugin!

First we need to open functions.php file. This file is located in our theme directory. Paste there this code:

Then on any page or post you can display message from this shortcode by writing this:


The best method in WordPress is using the dedicated type of block: shortcode.

If you want you can use any HTML formatting in your shortcode, eg.:

function my_shortcode() {
    $message = '<h1 style="font-size:60px; font-weight: bold;">My big HEADING</h1>';
    return $message;
add_shortcode('my_heading', 'my_shortcode');

As you see in the second line, I used here CSS formatting.