I use the following script to create a thumbnail shortcode, but this will only work at a loop or inside the post.
/* Thumb Shortcode */
function my_img() {
if (has_post_thumbnail() ) {
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'medium');
$image_url = $image_url[0];
$result = '<img src="'.$image_url.'" class="my_img" />';
return $result;
}
return;
}
add_shortcode ('my_img', 'my_img');
Is there any simple way to modify it, so that I can use it everywhere with a post ID?
Like this:
<?php echo do_shortcode('[my_img post="100"]'); ?>