0

I have a WordPress site using the following criteria from a plugin called MyCRED to determine whether to display content to the user, however that include consists of shortcodes and other non-PHP content. Is there a way to tell PHP 'treat this as if it is not PHP'? Shortcodes are key.

$minimum = 100;
if ( is_user_logged_in() && ( function_exists( 'mycred_get_users_cred' ) && mycred_get_users_cred( get_current_user_id() ) >= $minimum ) ) {
}

2 Answers 2

1

In your case do_shortcode should do the trick.

If your shortcode is just like [my_shortcode] then try echo do_shortcode( '[my_shortcode]' );

If you have opening and closing then echo do_shortcode( '[my_shortcode]Inner text[/my_shortcode]' );

2
  • What if we wanted to include not only shortcodes but other content as well? Nov 20, 2016 at 7:33
  • 1
    Try like this: echo 'Other content before ' . do_shortcode( '[my_shortcode]Inner text[/my_shortcode]' ) . ' Other content after'; :) Nov 20, 2016 at 9:05
1

The do_shortcode function should work:

echo do_shortcode('[shortcode]');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.