Title: if has_membership() php function
Last modified: August 30, 2016

---

# if has_membership() php function

 *  [MYGM](https://wordpress.org/support/users/mygm/)
 * (@mygm)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/if-has_membership-php-function/)
 * Hi,
    I am trying figure out how to use a function such as has_membership() to
   do php if/else statements in my theme template pages.
 * For example, certain dropdown links will only be visible to members with membership
   id 1, so in my header.php page I would do —
 *     ```
       <?php if (has_membership(1)) { ?>
       //code..
       <?php } else { ?>
       //more code...
       <?php } ?>
       ```
   
 * [https://wordpress.org/plugins/membership/](https://wordpress.org/plugins/membership/)

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

 *  Plugin Author [Bojan Radonic – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support4/)
 * (@wpmudev-support4)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/if-has_membership-php-function/#post-6647790)
 * Hey there MYGM,
 * How are you doing today?
 * Since you’re mentioning header.php I’m assuming you want to hide specific menu
   links for members in different membership levels.
 * If that is the case you should be able to do that with menu item protection. 
   To set those protection rules please go to Membership 2 -> Protection Rules -
   > Menu Items.
 * Hope this helps 🙂
 * Cheers,
    Bojan
 *  Thread Starter [MYGM](https://wordpress.org/support/users/mygm/)
 * (@mygm)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/if-has_membership-php-function/#post-6647793)
 * Hi thanks for the response however my links are custom coded and I need more 
   control than that within my theme templates. Is there a code snippet you can 
   provide?
 *  Plugin Author [Bojan Radonic – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support4/)
 * (@wpmudev-support4)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/if-has_membership-php-function/#post-6647843)
 * Hey again MYGM,
 * This is pretty close on what you need to do, you just missed a proper function
   name, please try using the following:
 *     ```
       <?php if ( ms_has_membership(190) ) { ?>
       //code..
       <?php } else { ?>
       //more code...
       <?php } ?>
       ```
   
 * 190 is the membership ID.
 * Hope this helps 🙂
 * Cheers,
    Bojan
 *  Thread Starter [MYGM](https://wordpress.org/support/users/mygm/)
 * (@mygm)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/if-has_membership-php-function/#post-6647857)
 * Thanks that seems to be it. However the membership id, is that a unique number
   per user? Cause I was looking to use numbers that correlate to the actual membership
   levels?
 *  Plugin Support [Saurabh – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support7/)
 * (@wpmudev-support7)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/if-has_membership-php-function/#post-6647916)
 * Hi [@mygm](https://wordpress.org/support/users/mygm/)
 * That would be the membership id not the userid, to get the membership level ID,
   simply hover over the edit membership level in the membership levels list and
   in the status bar you will see the membership_id.
 * Hope this helps.
 * Have a great day!

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

The topic ‘if has_membership() php function’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/membership_b8cdaa.svg)
 * [Membership 2](https://wordpress.org/plugins/membership/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/membership/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/membership/)
 * [Active Topics](https://wordpress.org/support/plugin/membership/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/membership/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/membership/reviews/)

## Tags

 * [else](https://wordpress.org/support/topic-tag/else/)
 * [functions](https://wordpress.org/support/topic-tag/functions/)
 * [if](https://wordpress.org/support/topic-tag/if/)
 * [levels](https://wordpress.org/support/topic-tag/levels/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [templates](https://wordpress.org/support/topic-tag/templates/)

 * 5 replies
 * 3 participants
 * Last reply from: [Saurabh – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support7/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/if-has_membership-php-function/#post-6647916)
 * Status: not resolved