Title: PHP for enclosed shortcodes
Last modified: August 19, 2016

---

# PHP for enclosed shortcodes

 *  Resolved [ericgallagher](https://wordpress.org/support/users/ericgallagher/)
 * (@ericgallagher)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/php-for-enclosed-shortcodes/)
 * I have a plugin that is using shortcodes and requires a closing shortcode. The
   two codes are [emember_protected for=3-4-5] & [/emember_protected].
 * I would like to hardcode this outside of the loop. I have read through the Codex,
   but am having a hard time understanding. Seems like most info there is to help
   WRITE shortcodes.

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/php-for-enclosed-shortcodes/#post-1925979)
 * do you menan:
 * do_shortcode()
    [http://codex.wordpress.org/Function_Reference/do_shortcode](http://codex.wordpress.org/Function_Reference/do_shortcode)
 *  Thread Starter [ericgallagher](https://wordpress.org/support/users/ericgallagher/)
 * (@ericgallagher)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/php-for-enclosed-shortcodes/#post-1925995)
 * That works for the opening shortcode. In my reading and my trial run though it
   does not work for the closing shortcode.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/php-for-enclosed-shortcodes/#post-1926004)
 * this is not working?
 * `<?php do_shortcode('[emember_protected for=3-4-5] & [/emember_protected]'); ?
   >`
 *  Thread Starter [ericgallagher](https://wordpress.org/support/users/ericgallagher/)
 * (@ericgallagher)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/php-for-enclosed-shortcodes/#post-1926005)
 * Have not tried that I guess. Where would I put the content that goes in between?
   It is a membership plugin that hides content between the two shortcodes.
 *  Thread Starter [ericgallagher](https://wordpress.org/support/users/ericgallagher/)
 * (@ericgallagher)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/php-for-enclosed-shortcodes/#post-1926007)
 * Nevermind, tested this and seems to work.
    `<?php do_shortcode('[emember_protected
   for=3-4-5] Content Here [/emember_protected]'); ?>`
 *  Thread Starter [ericgallagher](https://wordpress.org/support/users/ericgallagher/)
 * (@ericgallagher)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/php-for-enclosed-shortcodes/#post-1926008)
 * But….I need to add more PHP in this code and that does not work. Sorry do not
   know much about PHP. Can use any help you can offer though! Here is what I have
   now that does NOT work.
    `<?php echo do_shortcode('[emember_protected for=3-4-
   5] <a href="<?php echo get_post_meta( $post->ID, '_ct_text_4d60a199efcc8', true);?
   >"><img src="http://preparedcatholic.com/wp-content/uploads/2011/02/download_supporter.
   jpg" /></a> [/emember_protected]'); ?>`
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/php-for-enclosed-shortcodes/#post-1926015)
 * do not to use ‘echo’ within the code, keep it to strings and function that return
   strings.
    the code is already in a php area, so you can’t use the php tag.
 * also, as the string started with a single quotation mark ‘ you must use double
   quotations marks ” in the codes within.
 * try:
    `<?php echo do_shortcode('[emember_protected for=3-4-5] <a href="' . get_post_meta(
   $post->ID,"_ct_text_4d60a199efcc8", true ) . '"><img src="http://preparedcatholic.
   com/wp-content/uploads/2011/02/download_supporter.jpg" /></a> [/emember_protected]');?
   >`
 *  Thread Starter [ericgallagher](https://wordpress.org/support/users/ericgallagher/)
 * (@ericgallagher)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/php-for-enclosed-shortcodes/#post-1926018)
 * Perfect! Thanks! Also, thanks for the quick lesson on PHP. Every little bit helps
   and am slowly learning.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/php-for-enclosed-shortcodes/#post-1926019)
 * you are welcome 😉

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

The topic ‘PHP for enclosed shortcodes’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 9 replies
 * 2 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/php-for-enclosed-shortcodes/#post-1926019)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
