I made a custom User Panel which is similar to Wordpress Top Panel in page.tpl.php so this panel will be shown for every logged-in users on the top of their page. But I want to hide that panel in user-profile.tpl.php but, not sure is there any function like is_profile() or something like that so I can check for a profile page and when the statement is true then hide the custom User Panel on user-profile.tpl.php.

Note that my d7 site has its custom user profile page.

Any idea? Thanks

  • On the block's settings you have Pages tab with All pages except those listed - why can't you just use that? PS there is no need for bold "call to arms" text, your question was just as clear without it.
    – Mołot
    Aug 28, 2013 at 7:29
  • Thanks, i have edited my question, it should not be a Block i did a mistake in my Q;
    – rakibtg
    Aug 28, 2013 at 7:45
  • Please don't use `code marks` for things that are not code.
    – Mołot
    Aug 28, 2013 at 7:48

2 Answers 2


Anywhere in code, you can use code like that:

if (    arg(0) == 'user' // test if you are on user page
    and is_numeric(arg(1)) // and if user ID was provided and is possibly valid (a number)
    and arg(2) == FALSE // and there is no /edit or /delete added
) {
  // Do something

Substitute 'user' with any name provided by module, if you are using alternative user profile module.

  • If adding this to a module, would it go in hook_init()? I absolutely hate using hook_init and am looking for a better solution if someone could recommend one. Feb 5, 2016 at 16:04
  • this wrong, the path '/user/{username}' also points to the same user profile page. arg(1) won't always be numeric. Look at my answer
    – ShanjayG
    Oct 13, 2019 at 21:15
  • @SanjokGurung this answer is years old. Currently I am no longer working with Drupal, and keeping my knowledge up to date doesn't bring home the bacon, so I currently do not care. If you can improve community knowledge, great! By all means do it.
    – Mołot
    Oct 13, 2019 at 21:23
  • @Mołot, actually, your answer is correct , and I have to apologise.
    – ShanjayG
    Oct 13, 2019 at 21:50

You can do that in the Block configuration page. Click on 'configure block' on the contextual menu, or in blocks administration page admin/structure/block.

Below, under Visibility Settings make sure the All pages except those listed is selected, and in the textarea put this line:


If you are using Profile2 module, you may want to add also:


Where the profile-name is the machine name of your profile type.


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.