Did you wonder that you can easily build up a shortcode in wordpress not using any plugin. Using to much plugin can cause too much resource in your website that lead slow performance consider see this blog post for more information How to Speed Up Your WordPress Page Speed?

I will guide you how to build your own shortcode  wordpress in an easy way.

Final Code

function my_own_shortcode( $attr ) {
     $name = $attr['name'];
     $age = $attr['age'];
     
     $output = 'Name: ' . $name;
     $output .= 'Age: ' . $age;   
     return $output;  
}
add_shortcode( 'own_shortcode', 'my_own_shortcode' );

Converting this into shortcode you will use like this [own_shortcode name=”John Doe” age=”20″].

You can add this code to the function.php of your themes, be careful use sftp or ftp when doing this tutorial or you will going to miss up your website if you are editing the code at your cms backend.

I will explain the code this add_shortcode is the hook functionality build in to wordpress. This functionality code help you to create your own shortcode. You can visit this codex shortcode for more info about shortcode wordpress. As you can see I created my own shortcode functionality and pass to add_shortcode function this will tell how will the shortcode will return.

Inside of the my_own_shortcode function is where the content you want to output. As you can see is just a simple passing functionality so you can understand what I am doing hehe more of advanced build up shortcode functionality soon. Passing parameters $attr is where you can extend your shortcode as passing variable content so you can easily control dynamically what will be the output are as you can see it here [own_shortcode name=”John Doe” age=”20″] name is the first $attr[‘name’] and age is the second $attr[‘age’] you can change that any variable that you want as long they are the same passing variable. And finally you will just return the output.

You can use this shortcode at the backend and it will output the content. When you are advanced wordpress developer or php developer use it like this <?php echo do_shortcode(‘[own_shortcode name=”Laurince Quijano” age=”20″]’); ?>.

I will explain this further in my advance shortcode tutorial soon for now this is for beginner level to know what is shortcode all about.