Alejandro Garrido
Alejandro Garrido

Reputation: 519

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...

Upvotes: 0

Views: 288

Answers (1)

Thomas Durrenberger
Thomas Durrenberger

Reputation: 36

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; ?>

Upvotes: 2

Related Questions