In my site the www.example/user/uid path contains the view and edit tabs. I want to add some blocks to only the view page and not edit page.

Using "user/* (Only the listed pages)" under the visibility settings of block configuration attaches the block to both pages.

How can I make it appear on only the view page.

Thanks in anticipation.

3 Answers 3


Hope this will help you,

In Drupal 7,

  • You can achive it by enabling PHP filter module, which allows embedded PHP code/snippets to be evaluated. GO to admin > modules and enable PHP filter.
        global $user;
        if (arg(0) == 'user' && $user->uid == arg(1) && is_numeric(arg(1)) && (arg(2) == NULL) ){
          return TRUE;
        else {
          return FALSE;
    enter image description here
  • You can also refer Extended block visibility module. This will allows PHP block visibility to be defined in code.
  • Thanks, but please i do not understand this code or how to apply it.
    – seyi
    Jul 25, 2013 at 11:46
  • When user is viewing the his profile, then the arguments will be user and user ID. So Im checking arg(0) == 'user' and arg(1) must be numeric. If it is the user edit page, then arg(2) will be not NULL. So I'm checking for all the 3 conditions.
    – Inizio
    Jul 25, 2013 at 11:55
  • Enjoy coding :)
    – Inizio
    Jul 25, 2013 at 12:38
  • 1
    But this method requires that you enable the PHP Filter module which I never do. (Side note: In D6 you didn't need to enable the PHP Filter module to use PHP for block visibility - I'd be interested in a link to the issue that changed this if anyone can find it). Anyway, IMHO this logic should be moved to a module because the PHP Filter module is a deal-breaker. Jul 25, 2013 at 15:22

you could write some php in the visibility settings checking the path like:

 $path = explode('/', $_GET['q']);
 if ($path[0] == 'user') {
   if (is_numeric($path[1]) && $path[2] != 'edit') {
     return TRUE;

...something like that (untested). This could be handled in a user_view hook also, but this the simple solution.

Be carefull what PHP you write in there because if it breaks the site you will have to remove this code form block's records in the database!

  • Thanks. The code by @inizio works fine when added to the visibility settings.
    – seyi
    Jul 25, 2013 at 12:12

I would enable Panels and Page Manager and under Pages enable the user_view variant. Then place the block in where you want it in the layout.

You will also need to place normal "user" elements in the layout to not suddenly display nothing :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.