Creating shortcode in wordpress

In function.php define the shortcode using add_shortcode:

function myshortcode(){
global $post;
echo “My post id: “.$post->ID;
}
add_shortcode( ‘myshortcodehere’, ‘myshortcode’ );

Here we created a shortcode with na”myshortcodehere” To print the id of current post.

Call this shortcode as do_shortcode:

<?php echo do_shortcode(‘[myshortcodehere]’); ?>