How to display selected block only for a logged in or not logged in users

Last modified: October 29, 2009 - 22:54

If you have a block that you want to set visible only for logged in users, follow these easy steps:

1. Go to Administration -> Build -> Blocks page;
2. Select "Configure" link next to the name of the block that you want to set visible only for logged in users;
3. After the page reloads scroll down to the "Page specific visibility settings" field, select "Show if the following PHP code returns TRUE (PHP-mode, experts only)" option and paste the following code in the field "Pages" showed below the selection options:

<?php
 
global $user;
  return (bool)
$user->uid;
?>

To display the block only for anonymous users use the following code:

<?php
 
global $user;
  return !(bool)
$user->uid;
?>

Please note: to use this method the PHP filter module must be enabled!

 
 

Drupal is a registered trademark of Dries Buytaert.