• Resolved tone4407

    (@tone4407)


    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 to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor etoilewebdesign

    (@etoilewebdesign)

    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.

    Thread Starter tone4407

    (@tone4407)

    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

    (@tone4407)

    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.