Hide a block on all admin pages | Drupal 6

There are two main ways to do disable a certain block on all admin pages. The first way involves using the administrative tools provided in the backend. The second uses custom script.

-----------------------------------option 1 -----------------------------------------------

To disable a block on all admin pages go to

admin

then under Site building

click on blocks

Choose a block

Click configure

Choose "Show on every page except the listed pages."

Then in the field below enter

admin*

node/*/edit

node/add*

and then save (this is assuming you consider all edit pages as admin pages. Just something to consider. node/*/edit and node/add/* are typically missed as administration pages.)

You also might want to disable some modules like webforms and others that you may have installed.

node/*/webform

This should remove that block from all admin pages

The block will show up on all pages except the admin pages

if you used admin/* all admin pages except the home administrator page would be excluded

-----------------------------------option 2 -----------------------------------------------

if you want to use PHP then select "Show if the following PHP code returns"

< ?php
global $user;
$url = $_GET['q'];
if ( preg_match('/^admin/', $url) || preg_match('/^\/admin/', $url) )
{
//if you are on an admin page don't show the nab
return FALSE;
// block will be shown
} else if ( (bool) $user->uid ) {
return TRUE;
}
return FALSE;
? >

< ?php
if ( arg(0) == 'admin' || arg(2) == 'edit' || arg(1) == 'add' || arg(2) == 'webform'){
return FALSE;
}

return TRUE;
? >

oh yea ...booya!
on another note you can assume that a user cannot access any of the admin pages unless they are logged in. So if they are logged in don't show the block. Of course this is problematic if you want it to show for logged in users just not on the admin pages.


global $user;
if ( $user->uid != 0){
return FALSE;
}

return TRUE;
?>

Since it is problematic to just hide the block if the user is logged in you could just hide the block based on if the user has an administrative role:


global $user;
$approved_roles = array('adminrole1', 'adminrole2', 'adminrole3');

if (is_array($user->roles)) {
if (count(array_intersect($user->roles, $approved_roles)) > 0) {
return TRUE;
} else {
return FALSE;
}}
?>



comments powered by Disqus