Title: echo do_shortcode?
Last modified: September 19, 2017

---

# echo do_shortcode?

 *  Resolved [phantasmix](https://wordpress.org/support/users/phantasmix/)
 * (@phantasmix)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/echo-do_shortcode-2/)
 * I want to use the role filter like this:
 * `<?php echo do_shortcode( '[members_access role="' . echo $roles; '"]' ); ?>`
 * where $roles come from an Advanced Custom Fields Repeater. Doesn’t seem to work
   though. Everything else works, but not when I wrap it all up in do_shortcode.
   Can this shortcode be called like this?
 * Thank you

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

 *  Thread Starter [phantasmix](https://wordpress.org/support/users/phantasmix/)
 * (@phantasmix)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/echo-do_shortcode-2/#post-9511218)
 * Really helps to talk it out sometimes 🙂
 * There was a typo and an unnecessary ‘echo’. So here’s the working line:
 * `<?php echo do_shortcode( '[members_access role="' . $roles . '"]' ); ?>`
 *  Thread Starter [phantasmix](https://wordpress.org/support/users/phantasmix/)
 * (@phantasmix)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/echo-do_shortcode-2/#post-9511245)
 * Spoke too soon. It doesn’t break the page, but the shortcode isn’t filtering 
   the content based on the role, and I’ve got a stray tag showing from the closing
   do_shortcode
 * `[/members_access]`
 *  Thread Starter [phantasmix](https://wordpress.org/support/users/phantasmix/)
 * (@phantasmix)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/echo-do_shortcode-2/#post-9511463)
 * ——-
 *  [Justin Tadlock](https://wordpress.org/support/users/greenshady/)
 * (@greenshady)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/echo-do_shortcode-2/#post-9511511)
 * Simplest way to do this with Members:
 *     ```
       <?php if ( is_user_logged_in() && members_user_has_role( get_current_user_id(), $roles ) ) : ?>
   
       	HTML goes here.
   
       <?php endif; ?>
       ```
   
 * I’m assuming `$roles` is an array of roles.
 * ——
 * Shortcodes aren’t really a great way to do things like this. Use PHP instead.
 *  Thread Starter [phantasmix](https://wordpress.org/support/users/phantasmix/)
 * (@phantasmix)
 * [8 years, 8 months ago](https://wordpress.org/support/topic/echo-do_shortcode-2/#post-9511538)
 * Thanks. That’s the direction I went in with the last (edited) message 🙂
 * Though still stuck, I suspect it’s to do with ACF now, because $roles is a repeater
   checkboxes field and I always get stuck at those.
 * Thank you for your help, I’m sure once the ACF thing is figured out, the above
   will work.

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

The topic ‘echo do_shortcode?’ is closed to new replies.

 * ![](https://ps.w.org/members/assets/icon-256x256.png?rev=3508404)
 * [Members - Membership & User Role Editor Plugin](https://wordpress.org/plugins/members/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/members/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/members/)
 * [Active Topics](https://wordpress.org/support/plugin/members/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/members/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/members/reviews/)

## Tags

 * [do_shortcode](https://wordpress.org/support/topic-tag/do_shortcode/)

 * 5 replies
 * 2 participants
 * Last reply from: [phantasmix](https://wordpress.org/support/users/phantasmix/)
 * Last activity: [8 years, 8 months ago](https://wordpress.org/support/topic/echo-do_shortcode-2/#post-9511538)
 * Status: resolved