简体   繁体   中英

Wordpress shortcodes working on WP editor but not on PHP files

I'm using Memberium to create a membership site. To set the different levels of memberships I need to use shortcodes. I need to write these shortcodes in the template files but they only works on Wordpress editor.

I'm trying this:

<?php echo do_shortcode('[memb_has_membership memberships=normal]');?>

<h1>HELLO</h1>

<?php echo do_shortcode('[/memb_has_membership]');?>

Also, I have been tried without the echo, and writing only HTML...

Have you tried combining everything into one call?

<?php 

$str = "[memb_has_membership memberships=normal]<h1>HELLO</h1>[/memb_has_membership]";
echo do_shortcode($str);

?>

A cleaner way would be to use the plugin's PHP functions directly in your code.

The shortcode's function is member_hasMembership() ( Documentation )

<?php if(memb_hasMembership( ‘Gold’ )): ?>

    <h1>HELLO</h1>

<?php endif; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM