• Resolved paulmc911

    (@paulmc911)


    Hi all

    I’m having a bit of a problem inserting some shortcode (for a contact form) in between two other shortcodes. Basically, when I insert the shortcode for the form in between the other shortcode parameters, it disables it. I have read that I need to use the do_shortcode, and I’ve read the codex info on this but I’m too much the novice to be able to interpret, from those instructions, how I can use it to make my shortcode-within-shortcode work! Can anybody explain how I would use it in that instance? I know it’s a pain when someone asks basic questions but I HAVE tried to get my head round this, truly!

    Thanks

    Paul

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi Paul,

    What is the shortcode that you are trying to use?

    Also, not all shortcodes can be nested within other shortcodes.

    Evan

    Thread Starter paulmc911

    (@paulmc911)

    Hi Evan

    Well my page goes like this:

    [visitor]
    some text that appears to non logged-in users
    [/visitor]

    [member]
    some text that appears to logged-in users, and this form:
    [contact-form-7 id=”26″ title=”Submit your work”]
    [/member]

    It all works fine, other than the contact form, which is spot on UNTIL I wrap it in the [member] shortcodes. Then it just appears as the string of shortcode, and not as a form.

    If that makes sense?

    Thanks

    Paul

    where do those [visistor] and [member] shortcode come from?
    from a plugin?
    from your theme?

    what is the full exact code of each of these shortcode functions?

    Thread Starter paulmc911

    (@paulmc911)

    Hi Alchymyth,

    I got them from a forum somewhere, and they work fine except for this case. Here’s the code I put in my functions.php:

    add_shortcode( 'visitor', 'visitor_check_shortcode' );
    
    function visitor_check_shortcode( $atts, $content = null ) {
    	 if ( ( !is_user_logged_in() && !is_null( $content ) ) || is_feed() )
    		return $content;
    	return '';
    }
    
    add_shortcode( 'member', 'member_check_shortcode' );
    
    function member_check_shortcode( $atts, $content = null ) {
    	 if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
    		return $content;
    	return '';
    }

    and then I have wrapped the appropriate text on the page with the shortcodes as follows:

    [visitor]
    some text that appears to non logged-in users
    [/visitor]

    [member]
    some text that appears to logged-in users and this form:
    [contact-form-7 id=”26″ title=”Submit your work”]
    [/member]

    The problem is that with the [/member] shortcode in place, it disables the contact form 7 shortcode. So that it appears on the page exactly as it does above, and doesn’t display the form. If I remove the [/member] shortcode, the contact form works again. But I need the [/member] shortcode! Any ideas what I’ve done wrong?

    Thanks

    Paul

    in both functions, try to replace this line:

    return $content;

    with:

    return do_shortcode( $content );

    https://codex.ww.wp.xz.cn/Function_Reference/do_shortcode

    also, please fully review https://codex.ww.wp.xz.cn/Shortcode_API

    Thread Starter paulmc911

    (@paulmc911)

    Alchymyth you are a legend – it worked. Thank you so much. I have read that codex many times and from that I understood the need to apply do_shortcode, but I just couldn’t make it work or determine where it should go. Honestly, I’m not a lazy learner – I genuinely tried (a lot!) with this. Thanks again.

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

The topic ‘Use of do_shortcode function’ is closed to new replies.