Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I tell a block to appear on user profiles, like /user/1, but not on other pages where the beginning of the path is the same? So for instance, if I have a view set up at /user/1/articles, or user/1/messages, how can I tell the block to appear in the main user profile but not on the articles or messages pages?

share|improve this question
up vote 1 down vote accepted

I believe your only option is to use a PHP snippet to set the visibility.

Under Visibility settings select Pages on which this PHP code returns TRUE (experts only) copy and paste the snippet below.

if (arg(0) == 'user' && !arg(2)) return TRUE;

For this to work you would also need to enable the PHP filter module.

Note that it's not generally recommended to use the PHP filter, but in some cases it might be the easiest solution.

share|improve this answer
Yeah that ended up working. Why exactly is it not recommended to use the php filter? – Mrweiner Jan 20 '13 at 5:09
Check out this answer, and this page on drupal.org for the general reasons. – enzipher Jan 20 '13 at 6:38
Very thorough. Thanks. – Mrweiner Jan 20 '13 at 7:28
You're welcome. – enzipher Jan 20 '13 at 7:51

Try making it visible only on


and only for authenticated user role.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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