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 ) ) {

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

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

The do_shortcode function should work:

echo do_shortcode('[shortcode]');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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