Wolf X Machina

Back to blog

Hide the PersonaBar from a Role in DNN

Posted in DNN on February 18, 2020

Vicenç Masanas asked an interesting question on the DNN Connect Group about hiding the PersonaBar for users that have edit permissions on a DNN module. I've had to do this on a client's website before because they have users who are in the "Content Editors" role on the website and we don't want to show the PersonaBar for them.

If you need to hide the PersonaBar in DNN 9+, you can use some simple CSS inside of your skin's .ascx file. Simply use some conditional code to detect the role of the user that's logged in and add some CSS inline to the page. Here's how you could do it:

  1. Open your skin file .ascx
  2. Add the following code:
    <% If DotNetNuke.Security.PortalSecurity.IsInRole("Content Editors") Then %> 
    	<style type="text/css">
    		#Body {
    			margin-left: 0;
    		}
    		.personalBarContainer {
    			display: none;
    		}
    	</style>
    <% End If %>
    
  3. Notice on the first line I have "Content Editors" - this is the exact name of the DNN Role in my portal. If you have a different role, like "Admins" or "Translators", then change this line
  4. Save your file
  5. Test it out by logging in as a user in that role. It shouldn't be present

This is one of those your mileage may vary solutions. Here are the caveats:

  • This only hides it through CSS but doesn't actually remove it from the source or improve the performance of the page
  • The code only affects one role so you might need to modify it to support multiple roles
  • This always matches if the user is in this role. So you might run into problems if the user belongs to multiple roles and one of those roles needs the PersonaBar.

This isn't a perfect solution by any means but it's definitely pretty easy and can help in a pinch. And the bonus is that this code isn't limited to CSS. You could put anything you want in there to customize the experience for a user in that role.

I hope that this code helps! If you're looking for more advanced skinning techniques, I would love to help you. Check out my page on expert DNN development.

Aaron Lopez

Aaron Lopez

Founder & Lead Developer at Wolf X Machina

Theme picker

Wolf X Machina

Next Level Interface Development for the DNN CMS

DNN themes, module design, and more from Wolf X Machina.

Learn More