Do you know about shortcodes in WordPress? It’s basically some text that you can add between square brackets and it turns into some feature on the front-end.
In this post, let’s look at how to create a shortcode in WordPress. It’s quite simple and the example below explains how we can create a simple shortcode called echo-hello –
function echo_hello_func() {
return 'Hello Hello Hello';
}
add_shortcode('echo-hello', 'echo_hello_func');
This code can be added to your theme’s functions.php file or via a third party plugin like code-snippets.
Once done, you will be able to add [echo-hello] shortcode in your posts/pages which will basically print Hello Hello Hello on the front-end.
We can of course do more complex stuff with it but I hope this gives you a basic idea on how to create a shortcode on a WordPress site.