Title: Insert Dynamic Shortcode into Template
Last modified: May 31, 2018

---

# Insert Dynamic Shortcode into Template

 *  Resolved [tone4407](https://wordpress.org/support/users/tone4407/)
 * (@tone4407)
 * [8 years ago](https://wordpress.org/support/topic/insert-dynamic-shortcode-into-template/)
 * Hi,
 * I’m trying to add a shortcode on the template level. Here is what I have so far:
 * `<?php echo do_shortcode("[ultimate-reviews post_count='1' product_name='NEED_TO_ADD_PRODUCT_NAME_BASED_ON_CURRENT_PAGE']");?
   >`
 * I’ve also tried:
 * `<?php echo do_shortcode("[ultimate-reviews post_count='1' product_name='" . 
   $Product->Item_Name . "']"); ?>`
 * and
 * `<?php echo do_shortcode("[ultimate-reviews post_count='1' product_name='the_title();']");?
   >`
 * Neither worked.
 * It did work when I manually added the product name for one particular page:
 * `<?php echo do_shortcode("[ultimate-reviews post_count='1' product_name='Angle
   Broom']"); ?>`
 * However, this won’t work, because I need the product name to be dynamic and change
   based on the current page.
 * Any suggestions? Thanks!
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Finsert-dynamic-shortcode-into-template%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Contributor [etoilewebdesign](https://wordpress.org/support/users/etoilewebdesign/)
 * (@etoilewebdesign)
 * [8 years ago](https://wordpress.org/support/topic/insert-dynamic-shortcode-into-template/#post-10352051)
 * Hi tone,
 * Where are you doing this, in one of your theme’s template files? You’re trying
   to output the value of a variable that doesn’t exist at all in that file. You
   would need to query the correct database table and then output the product name
   field from the correct row in that table. This isn’t something we’ve tested, 
   so we cannot give guidance, beyond this, on how to go about it. Though, if you’re
   comfortable with coding, you should be able to achieve something like this.
    -  This reply was modified 8 years ago by [etoilewebdesign](https://wordpress.org/support/users/etoilewebdesign/).
 *  Thread Starter [tone4407](https://wordpress.org/support/users/tone4407/)
 * (@tone4407)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/insert-dynamic-shortcode-into-template/#post-10393126)
 * Hi, Etoile. Thanks for the response.
 * Yes, I’m trying to add the shortcode via the theme’s template file.
 * I’m well versed in coding, but not as well versed with WordPress sites. That 
   seems to be my hangup. I will see if I can figure out how to query the DB and
   output the product name field.
 * Thanks for your time.
 *  Thread Starter [tone4407](https://wordpress.org/support/users/tone4407/)
 * (@tone4407)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/insert-dynamic-shortcode-into-template/#post-10415982)
 * I was able to accomplish this like so:
 * `<?php echo do_shortcode('[ultimate-reviews post_count="1" product_name="'.get_the_title().'"]');?
   >`

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Insert Dynamic Shortcode into Template’ is closed to new replies.

 * ![](https://ps.w.org/ultimate-reviews/assets/icon-128x128.png?rev=1814372)
 * [Ultimate Reviews](https://wordpress.org/plugins/ultimate-reviews/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ultimate-reviews/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ultimate-reviews/)
 * [Active Topics](https://wordpress.org/support/plugin/ultimate-reviews/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ultimate-reviews/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ultimate-reviews/reviews/)

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 3 replies
 * 2 participants
 * Last reply from: [tone4407](https://wordpress.org/support/users/tone4407/)
 * Last activity: [7 years, 11 months ago](https://wordpress.org/support/topic/insert-dynamic-shortcode-into-template/#post-10415982)
 * Status: resolved