Title: Using shortcode in theme template
Last modified: August 21, 2016

---

# Using shortcode in theme template

 *  Resolved [yellowhippo](https://wordpress.org/support/users/yellowhippo/)
 * (@yellowhippo)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/using-shortcode-in-theme-template/)
 * Hi there,
 * Great plugin. I’m trying to add a message to all archive & post pages to non-
   members by embedding the shortcode [level-registered-no-subscription-expired-
   subscription] to my theme. I’ve tried the following:
 * echo do_shortcode(apply_filters(“the_content”, “[level-registered-no-subscription-
   expired-subscription]”));
 * echo do_shortcode(“[level-registered-no-subscription-expired-subscription]”]);
 * echo apply_filters( ‘the_content’,’ [level-registered-no-subscription-expired-
   subscription]” ‘);
 * None are working and just show a printed return.
 * Any thoughts? Do the shortcodes need to be registered first?
 * [https://wordpress.org/plugins/membership/](https://wordpress.org/plugins/membership/)

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

 *  [David](https://wordpress.org/support/users/ugotsta/)
 * (@ugotsta)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/using-shortcode-in-theme-template/#post-5075235)
 * Hi there [@yellowhippo](https://wordpress.org/support/users/yellowhippo/),
 * Hope you’re well today! 🙂
 * Fortunately, it’s actually easier doing this by code, you wouldn’t need the shortcodes.
   Instead, Membership provides some helpful functions.
 * You could use the following in conditional statements:
 *     ```
       current_user_is_member()
       current_user_has_subscription()
       current_user_on_level($level_id)
       current_user_on_subscription($sub_id)
       ```
   
 * So given those, you could maybe use a bit of code like this:
 *     ```
       if( current_user_has_subscription() ) {
           the_content();
       }
       ```
   
 * That would echo the content if the user has a subscription, otherwise it would
   do nothing. Or you could throw an else clause in there.
 * Would something like that work for you?
 * Cheers,
    David
 *  Thread Starter [yellowhippo](https://wordpress.org/support/users/yellowhippo/)
 * (@yellowhippo)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/using-shortcode-in-theme-template/#post-5075341)
 * Hi David,
 * Thank you for your quick response! I’m not sure why, but those statements are
   just being printed on the page and don’t seem to work as desired. I’m sure I’m
   missing something simple on my end, but I was actually able to find another solution
   using the access level permissions that accomplished what I was looking for.
 * Thank you!
 *  [David](https://wordpress.org/support/users/ugotsta/)
 * (@ugotsta)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/using-shortcode-in-theme-template/#post-5075350)
 * Hi [@yellowhippo](https://wordpress.org/support/users/yellowhippo/),
 * Oh, excellent! Glad you were able to find a viable solution without needing code.
   The plugin’s designed to make it as easy as possible to achieve everything without
   code, but code usually comes into play when you need things to work a very specific
   way.
 * Regarding the code getting rendered directly to the page, it would have be surrounded
   by PHP tags like so:
 *     ```
       <?php
       if( current_user_has_subscription() ) {
           the_content();
       }
       ?>
       ```
   
 * I thought you’d already had those, given your previous code post. But glad you’ve
   already got a great solution for this. 🙂
 * Cheers!

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

The topic ‘Using shortcode in theme template’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/membership_b8cdaa.svg)
 * [Membership 2](https://wordpress.org/plugins/membership/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/membership/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/membership/)
 * [Active Topics](https://wordpress.org/support/plugin/membership/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/membership/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/membership/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [David](https://wordpress.org/support/users/ugotsta/)
 * Last activity: [11 years, 11 months ago](https://wordpress.org/support/topic/using-shortcode-in-theme-template/#post-5075350)
 * Status: resolved