Information


Hiding Blocks in Drupal for Administrator

It is a curious oversight in the design of Drupal, that you can not directly control block visibility for the administrator by configuring the block.

The easiest way to hide a block when logged in as administrator, is to follow a modified version of the instructions on the Drupal site explaining the advanced use of block visibility.

This requires PHP, but you don’t actually have to know anything about PHP, just copy and paste the code below, as instructed. (View entire article to see code).

First, you have to set up the block so it will use the PHP code to decide if the block should be visible or not.

Then, you have to copy the code below into the pages field in the Show block on specific pages section.

Instructions

  1. Navigate to the blocks administration page.
  2. Click the configure link next to the block you want to control.
  3. Go to the section entitled Show Block on specific pages (at the bottom of the page, unless you have modules installed that add options below this section).
  4. Click the Show if the following PHP code returns TRUE option.
  5. Paste the following code into the Pages field.

<?php
global $user;
if ($user->uid != 1){
return TRUE;
} else {
return FALSE;
}
?>

This will evaluate true if user1 is logged in - user1 is always an administrator. If you have other users with an administer roll, you will have to change the following line:

if ($user->uid != 1){

to

if ($user->uid != 1 or $user->uid != # ){

where # is replaced by the user id of the other administrators. Keep adding “or $user->uid != #” for each administrator on your system.


Comments

No comments:

There are no comments for this post so far.

Post a comment