How to Display Content To Specific User Groups in Joomla in PHP

I use this code a lot and it's quite useful to have handy. This is code that works anywhere in a Joomla component or module that displays or hides content based on the current logged in users group status. You can add and minus the group ID's by removing or adding to the in_array line. To find the Joomla group ID's just goto Users > Groups and it's on the right hand furthest column. 


$user = JFactory::getUser();
$groups = $user->get('groups');
$isSuperAdmin = false;
if (in_array(8,$groups) || in_array(9,$groups) || in_array(14,$groups) || in_array(10,$groups) ){
	$isSuperAdmin = true;

<?php if ($isSuperAdmin) :?>ENTER CONTENT HERE<?php endif; ?>

 If you want to reverse it just add a ! to the front of $isSuperAdmin like so:

<?php if (!$isSuperAdmin) :?>ENTER CONTENT HERE<?php endif; ?>


Copyright © 2020 PromoMagic Ltd | +44 (0)1795859639 | This email address is being protected from spambots. You need JavaScript enabled to view it.

Registered in England and Wales Company Number: 11970723 -