WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] PHP for enclosed shortcodes (10 posts)

  1. ericgallagher
    Member
    Posted 3 years ago #

    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.

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

  3. ericgallagher
    Member
    Posted 3 years ago #

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

  4. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    this is not working?

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

  5. ericgallagher
    Member
    Posted 3 years ago #

    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.

  6. ericgallagher
    Member
    Posted 3 years ago #

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

  7. ericgallagher
    Member
    Posted 3 years ago #

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

  8. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

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

  9. ericgallagher
    Member
    Posted 3 years ago #

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

  10. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    you are welcome ;-)

Topic Closed

This topic has been closed to new replies.

About this Topic