Title: Display Shortcode for Specific Roles
Last modified: August 22, 2016

---

# Display Shortcode for Specific Roles

 *  Resolved [trickz100](https://wordpress.org/support/users/trickz100/)
 * (@trickz100)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/)
 * Hello,
 * I’ve been searching the interwebs for solutions on how to display a shortcode**
   only** when a specific role is logged in, but I can’t seem to find a solution.
 * I want the shortcode to display for Subscribers only, and not for anyone else,
   including those not logged in.
 * **[shortcode]Content Here[/shortcode]**
 * I simply want to hide **[shortcode][/shortcode]**, keeping ‘**Content Here**‘.
 * Any help would be greatly appreciated!

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

 *  [bernbe01](https://wordpress.org/support/users/bernbe01/)
 * (@bernbe01)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/#post-5822510)
 * hey
 * cool customization you’re applying! I like that thought process on the content
   perms
 * so the only way i can think of doing this is to use a plugin that allows you 
   to have multiple role-based-content-areas per page then i’d make one area with
   the shortcode you want, and another area for the roles of the users that didn’t
   match.
 * more like an if / else
 * i’m not super familiar with this plugin, but it would basically have shortcodes
   to identify the content areas, and then your shortcodes within. something like:
 *     ```
       [O_U user_role="Administrator"][shortcode]Content Here[/shortcode][/O_U]
   
       [O_U user_role="Author,Editor"]Content Here[/O_U]
   
       [O_U logged_status="out"]Guest Content Here[/O_U]
       ```
   
 * What do think? Worth trying?
 *  [bernbe01](https://wordpress.org/support/users/bernbe01/)
 * (@bernbe01)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/#post-5822511)
 * i forgot the link to [the plugin](https://wordpress.org/plugins/user-specific-content/)
   i was talking about 😛
 *  Thread Starter [trickz100](https://wordpress.org/support/users/trickz100/)
 * (@trickz100)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/#post-5822513)
 * Hello,
 * Thank you for your time to help out, but sadly it isn’t working on my website.
 * I’ll try to be more specific if I can;
 * I am using two plugins in each post that use shortcodes.
 * 1) Download Manager
    2) Advertising
 * The outcome: [pre_ad adid=”2957″][wpdm_package id=’23947′][/pre_ad]
 * Now, [wpdm_package id=’23947′] is “the content” and I need to hide [pre_ad adid
   =”2957″][/pre_ad] for everyone, except Subscribers.
 * I have tried a few plugins that involve wrapping these with yet another shortcode,
   but sadly it doesn’t seem to be working 🙁
 *  [bernbe01](https://wordpress.org/support/users/bernbe01/)
 * (@bernbe01)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/#post-5822514)
 * ok, no problem
 * is this something you’d be open to doing in the theme’s template file?
 * what is your theme? do you have a child theme currently?
 * and are the nest shortcodes that you are currently using functioning as expected?
 * thanks!
 *  Thread Starter [trickz100](https://wordpress.org/support/users/trickz100/)
 * (@trickz100)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/#post-5822516)
 * Hello,
 * Yes I’d be happy to modify theme files, I am using a different theme than the
   default WordPress themes.
 * > are the nest shortcodes that you are currently using functioning as expected?
 *  – I assume so, not sure.
 *  [bernbe01](https://wordpress.org/support/users/bernbe01/)
 * (@bernbe01)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/#post-5822517)
 * on the nested shortcode question, i am curious if when you put this:
 * `[pre_ad adid="2957"][wpdm_package id='23947'][/pre_ad]`
 * into the content if it renders or not. please let me know
 * it might be ok that it isn’t a default theme. which one is it?
 *  Thread Starter [trickz100](https://wordpress.org/support/users/trickz100/)
 * (@trickz100)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/#post-5822518)
 * > if it renders or not
 * – I am unsure how to check that :/
 *  [bernbe01](https://wordpress.org/support/users/bernbe01/)
 * (@bernbe01)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/#post-5822520)
 * thats no problem
 * when you were getting the sample code to show me that snippet, what area of wordpress
   did you extract it from? may I please have a link to the page as well?
 *  Thread Starter [trickz100](https://wordpress.org/support/users/trickz100/)
 * (@trickz100)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/#post-5822524)
 * It’s using two plugins, “WordPress Download Manager” and “WP Pre Advertisement”
 * The shortcodes were taken after generating download packages and advert packages.
 * Is there not a way of using [Strip Shortcodes](http://codex.wordpress.org/Function_Reference/strip_shortcodes)?
 * I am putting the shortcodes into every post. (I havn’t added the advert code 
   yet as I want to show it only to certain users, once the issue is solved, i’ll
   then add them to the over 2800 posts there are on the website)
 * My website is [http://www.astateoftrance.co.uk](http://www.astateoftrance.co.uk)
 *  [bernbe01](https://wordpress.org/support/users/bernbe01/)
 * (@bernbe01)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/#post-5822526)
 * strip shortcodes is a good idea, but i think it actually would remove both layers
   of shortcodes leaving us with no content either
 * one more plugin method to try if you are up to it?
 * [nested shortcodes plugin](https://wordpress.org/plugins/nested-shortcodes/) 
   will let us try these codes out (be sure to [edit the roles](https://en.support.wordpress.com/user-roles/)
   to your liking) so please install that and then try the following out on one 
   of the posts (or a new, non-browseable post):
 *     ```
       [O_U user_role="Author,Editor"][wpdm_package id='23947'][/O_U]
   
       [O_U logged_status="out"][pre_ad adid="2957"][wpdm_package id='23947'][/pre_ad][/O_U]
       ```
   
 * if that doesn’t work:
 * do you already have a [child theme](https://wordpress.org/plugins/child-theme-configurator/)
   or have you been customizing the raw theme files? child theme will allow you 
   to safely update the theme from envato
 * please [create a new page/post template](http://codex.wordpress.org/Page_Templates#Custom_Page_Template)
   based on the template in use by the posts you want to affect currently (you maye
   have to connect via ftp/panel/ssh to see the contents of that file)
 * after that create a [pastebin](http://pastebin.com/) of this template and update
   this thread with the link
 * i may need some more info then, depends what we see 😛
 *  [bernbe01](https://wordpress.org/support/users/bernbe01/)
 * (@bernbe01)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/#post-5822527)
 * i have to jet for a while. if i can i’ll get back on it this eve. i’ll check 
   back tomorrow at the latest though, ok?
 *  Thread Starter [trickz100](https://wordpress.org/support/users/trickz100/)
 * (@trickz100)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/#post-5822530)
 * Thanks for the info! I’ll look into it 🙂
 *  Thread Starter [trickz100](https://wordpress.org/support/users/trickz100/)
 * (@trickz100)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/#post-5822562)
 * Hello again,
 * Ok after a few hours playing with code and searching around online, I managed
   to come up with a working code to fit my needs!
 *     ```
       // REMOVE ADVERT SHORTCODE FOR EVERYONE EXCEPT SUBSCRIBERS //
   
       if( current_user_can('administrator') || current_user_can('premium_member') || !is_user_logged_in() ) {
       function remove_advert_first_part($content) {
       	return str_replace('[pre_ad adid="2957"]', '', $content);
       	}
       add_filter( 'the_content', 'remove_advert_first_part', 6);
       }
   
       if( current_user_can('administrator') || current_user_can('premium_member') || !is_user_logged_in() ) {
       function remove_advert_second_part($content) {
           return str_replace('[/pre_ad]', '', $content);
       }
       add_filter( 'the_content', 'remove_advert_second_part', 6);
       }
       ```
   
 * The above code will remove **[pre_ad adid=”2957″][/pre_ad]** for Administrators,
   Premium Members and those who are not logged in. It also keeps the content in
   between.
 * I’m not sure if you can place two parts of a shortcode within one function or
   not, but since I couldn’t figure that part out, I made two functions, one to 
   removed the first part of the shortcode, and one to remove the second and it 
   works just as well.
 * Thanks very much for your time and help still, it really means a lot and I hope
   this code can be of some use to others!
 * -Trickz100
 *  [bernbe01](https://wordpress.org/support/users/bernbe01/)
 * (@bernbe01)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/#post-5822565)
 * very nice work dude!!!!
 * I’m stoked to see your solution! thank you for posting it back, hopefully it’ll
   help someone else out someday too
 * feel free to mark this thread as resolved if you have no more questions as well
 * take care!
 *  Thread Starter [trickz100](https://wordpress.org/support/users/trickz100/)
 * (@trickz100)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/#post-5822566)
 * Thanks dude, all the best 🙂

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

The topic ‘Display Shortcode for Specific Roles’ is closed to new replies.

## Tags

 * [display](https://wordpress.org/support/topic-tag/display/)
 * [hide](https://wordpress.org/support/topic-tag/hide/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 15 replies
 * 2 participants
 * Last reply from: [trickz100](https://wordpress.org/support/users/trickz100/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/display-shortcode-for-specific-roles/#post-5822566)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
