Hide A Block On All Admin Pages | Drupal 6

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

To disable a block on all admin pages goto

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 nav
      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.

 

<?php
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:

<?php
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;
}}
?>

 

------------------------------------------

ps. You may note at the top that. I often spell "go to" as "goto" are you nerdy enough to guess why?....

 

because I learned to program basic around 10 years old and one of the most common statements I used was the goto statement. Ruined my spelling for life!...well thats not the only word I commonly mispell. I know I should correct it but I thought it would be more fun to note. Plus more content makes search engines happy even though this has nothing to do with this article...bla...bla...bla...yea google! :)

Trackback(0)
Comments (1)add comment

adam said:

should be
node/add*
 
report abuse
vote down
vote up
July 13, 2011
Votes: +0

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
smile
wink
laugh
grin
angry
sad
shocked
cool
tongue
kiss
cry
smaller | bigger

security image
Write the displayed characters


busy