• Resolved yellowhippo

    (@yellowhippo)


    Hi there,

    Great plugin. I’m trying to add a message to all archive & post pages to non-members by embedding the shortcode [level-registered-no-subscription-expired-subscription] to my theme. I’ve tried the following:

    echo do_shortcode(apply_filters(“the_content”, “[level-registered-no-subscription-expired-subscription]”));

    echo do_shortcode(“[level-registered-no-subscription-expired-subscription]”]);

    echo apply_filters( ‘the_content’,’ [level-registered-no-subscription-expired-subscription]” ‘);

    None are working and just show a printed return.

    Any thoughts? Do the shortcodes need to be registered first?

    https://ww.wp.xz.cn/plugins/membership/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi there @yellowhippo,

    Hope you’re well today! 🙂

    Fortunately, it’s actually easier doing this by code, you wouldn’t need the shortcodes. Instead, Membership provides some helpful functions.

    You could use the following in conditional statements:

    current_user_is_member()
    current_user_has_subscription()
    current_user_on_level($level_id)
    current_user_on_subscription($sub_id)

    So given those, you could maybe use a bit of code like this:

    if( current_user_has_subscription() ) {
        the_content();
    }

    That would echo the content if the user has a subscription, otherwise it would do nothing. Or you could throw an else clause in there.

    Would something like that work for you?

    Cheers,
    David

    Thread Starter yellowhippo

    (@yellowhippo)

    Hi David,

    Thank you for your quick response! I’m not sure why, but those statements are just being printed on the page and don’t seem to work as desired. I’m sure I’m missing something simple on my end, but I was actually able to find another solution using the access level permissions that accomplished what I was looking for.

    Thank you!

    Hi @yellowhippo,

    Oh, excellent! Glad you were able to find a viable solution without needing code. The plugin’s designed to make it as easy as possible to achieve everything without code, but code usually comes into play when you need things to work a very specific way.

    Regarding the code getting rendered directly to the page, it would have be surrounded by PHP tags like so:

    <?php
    if( current_user_has_subscription() ) {
        the_content();
    }
    ?>

    I thought you’d already had those, given your previous code post. But glad you’ve already got a great solution for this. 🙂

    Cheers!

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

The topic ‘Using shortcode in theme template’ is closed to new replies.