Hi Paul,
What is the shortcode that you are trying to use?
Also, not all shortcodes can be nested within other shortcodes.
Evan
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?
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
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.