Title: Use Shortcode inside Template
Last modified: August 21, 2016

---

# Use Shortcode inside Template

 *  [bleachie](https://wordpress.org/support/users/bleachie/)
 * (@bleachie)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/use-shortcode-inside-template/)
 * Hello,
 * New to wordpress and PHP.
 * How do I wrap this shortcode around some HTML/PHP? I’ve tried using the do_shortcode
   but that didn’t work.
 *     ```
       <?php echo do_shortcode( [timed-content-rule id="101"] ) ?> 
   
       <?php echo do_shortcode( [/timed-content-rule] ) ?>
       ```
   
 * **PHP/HTML**
 *     ```
       <?php
       $rows = get_field('breakfast');
       $row_count = count($rows);
       $i = rand(0, $row_count - 1);
   
       ?>
   
       <h1>
           <?php echo $rows[ $i ]['dish_name']; ?>
       </h1>
       <p>
          <?php echo $rows[ $i ]['dish_description'];  ?>
       </p>
       <h3>
           Served<span><?php echo $rows[ $i ]['time_served'];  ?></span>
       </h3>
       ```
   
 * [https://wordpress.org/plugins/timed-content/](https://wordpress.org/plugins/timed-content/)

Viewing 1 replies (of 1 total)

 *  Plugin Contributor [K. Tough](https://wordpress.org/support/users/kjvtough/)
 * (@kjvtough)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/use-shortcode-inside-template/#post-5059093)
 * Hi.
 * Put the content you want to protect into a variable, then wrap everything into
   a `do_shortcode()` call. It’ll look something like this:
 *     ```
       <?php
       $rows = get_field('breakfast');
       $row_count = count($rows);
       $i = rand(0, $row_count - 1);
   
       $my_timed_content = "<h1>" . $rows[$i]['dish_name'] . "</h1>";
       $my_timed_content .= "<p>" . $rows[$i]['dish_description'] . "</p>";
       $my_timed_content .= "<h3>Served<span>" . $rows[$i]['time_served'] . "</span></h3>";
       echo do_shortcode( '[timed-content-rule id="101"]' . $my_timed_content . '[/timed-content-rule]' );
       ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Use Shortcode inside Template’ is closed to new replies.

 * ![](https://ps.w.org/timed-content/assets/icon-256x256.png?rev=2953069)
 * [Timed Content](https://wordpress.org/plugins/timed-content/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/timed-content/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/timed-content/)
 * [Active Topics](https://wordpress.org/support/plugin/timed-content/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/timed-content/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/timed-content/reviews/)

## Tags

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

 * 1 reply
 * 2 participants
 * Last reply from: [K. Tough](https://wordpress.org/support/users/kjvtough/)
 * Last activity: [11 years, 11 months ago](https://wordpress.org/support/topic/use-shortcode-inside-template/#post-5059093)
 * Status: not resolved