Getting post ID within shortcode on page template <p>I am using a plugin called: InPost Gallery. I have added the shortcode to my page template so that I can show gallery on each page. Currently the shortcode has post_id="10" I need the post ID to change for each page to show images that below to each page, and to therefore use a code such as get_post_ID() however I'm currently unable to get this to work..</p> <p>Here is the relevant shortcode-</p> <pre><code>&lt;?php echo do_shortcode('[inpost_gallery thumb_width="100" thumb_height="100" post_id="10" thumb_margin_left="0" thumb_margin_bottom="0" thumb_border_radius="2" thumb_shadow="0 1px 4px rgba(0, 0, 0, 0.2)" js_play_delay="3000" id="" random="0" group="0" border="" type="yoxview" show_in_popup="0" album_cover="" album_cover_width="200" album_cover_height="200" popup_width="800" popup_max_height="600" popup_title="Gallery"][/inpost_gallery]'); ?&gt; </code></pre> <p>Here is my template PHP which incorporates this shortcode-</p> <pre><code> &lt;?php // album download start // if ( isset($_GET['download']) ) { // header('Content-type: application/mp3'); // header('Content-Disposition: attachment; filename='.basename($_GET['download'])); // readfile( $_GET['download'] ); // } // album download end get_header(); global $cs_transwitch,$prettyphoto_flag; $prettyphoto_flag = "true"; $cs_album = get_post_meta($post-&gt;ID, "cs_album", true); if ( $cs_album &lt;&gt; "" ) { $xmlObject = new SimpleXMLElement($cs_album); $cs_layout = $xmlObject-&gt;cs_layout; $cs_sidebar_left = $xmlObject-&gt;cs_sidebar_left; $cs_sidebar_right = $xmlObject-&gt;cs_sidebar_right; } if ( $cs_layout == "left" ) { $cs_layout = "two-thirds column right"; $show_sidebar = $cs_sidebar_left; } else if ( $cs_layout == "right" ) { $cs_layout = "two-thirds column left"; $show_sidebar = $cs_sidebar_right; } else $cs_layout = "sixteen columns left"; ?&gt; &lt;div id="container" class="container row"&gt; &lt;div role="main" class="&lt;?php echo $cs_layout;?&gt;" &gt; &lt;?php /* Run the loop to output the post. * If you want to overload this in a child theme then include a file * called loop-single.php and that will be used instead. */ //get_template_part( 'loop', 'single_cs_album' ); ?&gt; &lt;?php if ( have_posts() ): while ( have_posts() ) : the_post(); ?&gt; &lt;?php //showing meta start $cs_album = get_post_meta($post-&gt;ID, "cs_album", true); if ( $cs_album &lt;&gt; "" ) { $xmlObject = new SimpleXMLElement($cs_album); $cs_layout = $xmlObject-&gt;cs_layout; $cs_sidebar_left = $xmlObject-&gt;cs_sidebar_left; $cs_sidebar_right = $xmlObject-&gt;cs_sidebar_right; $album_release_date = $xmlObject-&gt;album_release_date; $album_social_share = $xmlObject-&gt;album_social_share; $album_buy_amazon = $xmlObject-&gt;album_buy_amazon; $album_buy_apple = $xmlObject-&gt;album_buy_apple; $album_buy_groov = $xmlObject-&gt;album_buy_groov; $album_buy_cloud = $xmlObject-&gt;album_buy_cloud; } //showing meta end ?&gt; &lt;div id="post-&lt;?php the_ID(); ?&gt;" &lt;?php post_class(); ?&gt;&gt; &lt;h1 class="heading"&gt;&lt;?php the_title(); ?&gt;&lt;/h1&gt; &lt;div class="in-sec"&gt; &lt;?php // getting featured image start $image_id = get_post_thumbnail_id ( $post-&gt;ID ); if ( $image_id &lt;&gt; "" ) { //$image_url = wp_get_attachment_image_src($image_id, array(208,208),true); $image_url = cs_attachment_image_src($image_id, 208, 208); $image_url = $image_url; //$image_url_full = wp_get_attachment_image_src($image_id, 'full',true); $image_url_full = cs_attachment_image_src($image_id, 0, 0); $image_url_full = $image_url_full; } else { $image_url = get_template_directory_uri()."/images/admin/no_image.jpg"; $image_url_full = get_template_directory_uri()."/images/admin/no_image.jpg"; } //$image_id = get_post_thumbnail_id ( $post-&gt;ID ); //$image_url = wp_get_attachment_image_src($image_id, array(208,198),true); //$image_url_full = wp_get_attachment_image_src($image_id, 'full',true); // getting featured image end ?&gt; &lt;div class="light-box album-tracks album-detail &lt;?php if($image_id == "") echo "no-img-found";?&gt; "&gt; &lt;div id="main-container"&gt; &lt;div id="leftcolumn"&gt; &lt;a rel="prettyPhoto" name="&lt;?php the_title(); ?&gt;" href="&lt;?php echo $image_url_full?&gt;" class="thumb" &gt; &lt;?php echo "&lt;img src='".$image_url."' /&gt;";?&gt; &lt;/a&gt; &lt;br&gt; &lt;br&gt; &lt;div id="inpostgallery"&gt;&lt;?php echo do_shortcode('[inpost_gallery thumb_width="104" thumb_height="104" post_id="10" thumb_margin_left="0" thumb_margin_bottom="0" thumb_border_radius="2" thumb_shadow="0 1px 4px rgba(0, 0, 0, 0.2)" js_play_delay="3000" id="" random="0" group="0" border="" type="yoxview" show_in_popup="0" album_cover="" album_cover_width="200" album_cover_height="200" popup_width="800" popup_max_height="600" popup_title="Gallery"][/inpost_gallery]'); ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="rightcolumn"&gt; &lt;div class="desc"&gt; &lt;p style="font-size:12px;"&gt;&lt;span class="bold" style="text-transform:uppercase; color:#262626;"&gt;&lt;?php _e('Categories', CSDOMAIN); ?&gt; :&lt;/span&gt; &lt;?php /* translators: used between list items, there is a space after the comma */ $before_cat = " ".__( '',CSDOMAIN ); $categories_list = get_the_term_list ( get_the_id(), 'album-category', $before_cat, ', ', '' ); if ( $categories_list ): printf( __( '%1$s', CSDOMAIN ),$categories_list ); endif; '&lt;/p&gt;'; ?&gt; &lt;/p&gt; &lt;br&gt; &lt;h4&gt;&lt;?php _e('Description', CSDOMAIN); ?&gt;&lt;/h4&gt; &lt;div class='txt rich_editor_text'&gt; &lt;?php the_content(); ?&gt; &lt;/div&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;?php edit_post_link( __( 'Edit', CSDOMAIN ), '&lt;span class="edit-link"&gt;', '&lt;/span&gt;' ); ?&gt; &lt;/div&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="in-sec"&gt; &lt;div class="album-opts"&gt; &lt;div class="share-album"&gt; &lt;?php $cs_social_share = get_option("cs_social_share"); if($cs_social_share != ''){ $xmlObject_album = new SimpleXMLElement($cs_social_share); if($album_social_share == 'Yes'){ social_share(); }?&gt; &lt;?php }?&gt; &lt;/div&gt; &lt;?php if($album_buy_amazon != '' or $album_buy_apple != '' or $album_buy_groov != '' or $album_buy_cloud != ''){?&gt; &lt;div class="availble"&gt; &lt;h4&gt;&lt;?php if($cs_transwitch =='on'){ _e('Buy This',CSDOMAIN); }else{ echo __CS('buy_now', 'Buy This'); }?&gt;&lt;/h4&gt; &lt;?php if ( $album_buy_amazon &lt;&gt; "" ) echo ' &lt;a target="_blank" href="'.$album_buy_amazon.'" class="amazon-ind"&gt;&amp;nbsp;&lt;span&gt;';if($cs_transwitch =='on'){ _e('Amazon',CSDOMAIN); }else{ echo __CS('amazon', 'Amazon'); } echo '&lt;/span&gt;&lt;/a&gt; '; if ( $album_buy_apple &lt;&gt; "") echo ' &lt;a target="_blank" href="'.$album_buy_apple.'" class="apple-ind"&gt;&amp;nbsp;&lt;span&gt;'; if($cs_transwitch =='on'){ _e('Apple',CSDOMAIN); }else{ echo __CS('itunes', 'iTunes'); } echo '&lt;/span&gt;&lt;/a&gt; '; if ( $album_buy_groov &lt;&gt; "") echo ' &lt;a target="_blank" href="'.$album_buy_groov.'" class="grooveshark-ind"&gt;&amp;nbsp;&lt;span&gt;'; if($cs_transwitch =='on'){ _e('GrooveShark',CSDOMAIN); }else{ echo __CS('grooveshark', 'GrooveShark'); } echo '&lt;/span&gt;&lt;/a&gt; '; if ( $album_buy_cloud &lt;&gt; "") echo ' &lt;a target="_blank" href="'.$album_buy_cloud.'" class="soundcloud-ind"&gt;&amp;nbsp;&lt;span&gt;'; if($cs_transwitch =='on'){ _e('SoundCloud',CSDOMAIN); }else{ echo __CS('soundcloud', 'SoundCloud '); } echo '&lt;/span&gt;&lt;/a&gt; '; ?&gt; &lt;/div&gt; &lt;?php }?&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php foreach ( $xmlObject as $track ){ if ( $track-&gt;getName() == "track" ) { ?&gt; &lt;div class="in-sec"&gt; &lt;?php enqueue_alubmtrack_format_resources(); ?&gt; &lt;div class="album-tracks light-box"&gt; &lt;?php $counter = 0; foreach ( $xmlObject as $track ){ $counter++; if ( $track-&gt;getName() == "track" ) { echo "&lt;div class='track'&gt;"; echo "&lt;h5&gt;"; echo $album_track_title = $track-&gt;album_track_title; echo "&lt;/h5&gt;"; echo "&lt;ul&gt;"; if ($track-&gt;album_track_playable == "Yes") { echo ' &lt;li&gt; &lt;div class="cp-container cp_container_'.$counter.'"&gt; &lt;ul class="cp-controls"&gt; &lt;li&gt;&lt;a style="display: block;" href="#" class="cp-play" tabindex="1"&gt;&amp;nbsp;&lt;span&gt;'; if($cs_transwitch =='on'){ _e('Play',CSDOMAIN); }else{ echo __CS('play', 'Play'); } echo '&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" class="cp-pause" style="display: none;" tabindex="1"&gt;&amp;nbsp;&lt;span&gt;'; if($cs_transwitch =='on'){ _e('Pause',CSDOMAIN); }else{ echo __CS('pause', 'Pause'); } echo '&lt;/span&gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div style="width: 0px; height: 0px;" class="cp-jplayer jquery_jplayer_'.$counter.'"&gt; &lt;img style="width: 0px; height: 0px; display: none;" id="jp_poster_0"&gt; &lt;audio src="'.$track-&gt;album_track_mp3_url.'" preload="metadata" &gt;&lt;/audio&gt; &lt;/div&gt; &lt;script&gt; jQuery(document).ready(function($){ var myCirclePlayer = new CirclePlayer(".jquery_jplayer_'.$counter.'", { mp3: "'.$track-&gt;album_track_mp3_url.'" }, { cssSelectorAncestor: ".cp_container_'.$counter.'", swfPath: "'.get_template_directory_uri().'/scripts/frontend/Jplayer.swf", wmode: "window", supplied: "mp3" }); }); &lt;/script&gt; &lt;/li&gt; '; } if ($track-&gt;album_track_downloadable == "Yes"){ echo '&lt;li&gt;&lt;a href="'.$track-&gt;album_track_mp3_url.'" class="download"&gt;&amp;nbsp;&lt;span&gt;'; if($cs_transwitch =='on'){ _e('Download',CSDOMAIN); }else{ echo __CS('download', 'Download'); } echo '&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;'; } if ($track-&gt;album_track_lyrics &lt;&gt; "") { echo '&lt;li&gt;&lt;a href="#lyrics'.$counter.'" rel="prettyPhoto[inline]" title="'.$album_track_title.'" class="lyrics"&gt;&amp;nbsp;&lt;span&gt;'; if($cs_transwitch =='on'){ _e('Lyrics',CSDOMAIN); }else{ echo __CS('lyrics', 'Lyrics'); } echo '&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;';} if ($track-&gt;album_track_buy_mp3 &lt;&gt; ""){ echo '&lt;li&gt;&lt;a href="'.$track-&gt;album_track_buy_mp3.'" class="buysong"&gt;&amp;nbsp;&lt;span&gt;'; if($cs_transwitch =='on'){ _e('Buy&amp;nbsp;Song',CSDOMAIN); }else{ echo __CS('buy_now', 'Buy&amp;nbsp;Song'); } echo '&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;';} echo "&lt;/ul&gt;"; echo ' &lt;div id="lyrics'.$counter.'" style="display:none;"&gt; '.str_replace("\n","&lt;/br&gt;",$track-&gt;album_track_lyrics).' &lt;/div&gt; '; echo "&lt;/div&gt;"; } } ?&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php } } ?&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;?php if ( get_the_author_meta( 'description' ) ) :?&gt; &lt;div class="in-sec" style="margin-top:20px;"&gt; &lt;div class="about-author"&gt; &lt;div class="avatars"&gt; &lt;?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'PixFill_author_bio_avatar_size', 53 ) ); ?&gt; &lt;/div&gt; &lt;div class="desc"&gt; &lt;h5&gt;&lt;a href="&lt;?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?&gt;"&gt;&lt;?php _e('About', CSDOMAIN); ?&gt; &lt;?php echo get_the_author(); ?&gt;&lt;/a&gt;&lt;/h5&gt; &lt;p class="txt"&gt; &lt;?php the_author_meta( 'description' ); ?&gt; &lt;/p&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php endif; ?&gt; &lt;/div&gt; &lt;?php endwhile; endif; // end of the loop. ?&gt; &lt;?php comments_template( '', true ); ?&gt; &lt;/div&gt; &lt;?php if( $cs_layout != "sixteen columns left" and isset($show_sidebar) ) { ?&gt; &lt;!--Sidebar Start--&gt; &lt;div class="one-third column left"&gt; &lt;?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar($show_sidebar) ) : ?&gt; &lt;?php endif; ?&gt; &lt;/div&gt; &lt;!--Sidebar Ends--&gt; &lt;?php }?&gt; &lt;div class="clear"&gt;&lt;/div&gt;&lt;!-- #content --&gt; &lt;/div&gt;&lt;!-- #container --&gt; &lt;div class="clear"&gt;&lt;/div&gt; &lt;?php get_footer(); ?&gt; </code></pre>