Support » How-To and Troubleshooting » [Resolved] PHP for enclosed shortcodes

[Resolved] 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)
  • Moderator Michael


    That works for the opening shortcode. In my reading and my trial run though it does not work for the closing shortcode.

    Moderator Michael


    this is not working?

    <?php do_shortcode('[emember_protected for=3-4-5] & [/emember_protected]'); ?>

    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.

    Nevermind, tested this and seems to work.
    <?php do_shortcode('[emember_protected for=3-4-5] Content Here [/emember_protected]'); ?>

    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]'); ?>

    Moderator Michael


    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.

    <?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]'); ?>

    Perfect! Thanks! Also, thanks for the quick lesson on PHP. Every little bit helps and am slowly learning.

    Moderator Michael


    you are welcome 😉

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘[Resolved] PHP for enclosed shortcodes’ is closed to new replies.