How to remove "member for" from the user profile page?

looklively - July 23, 2007 - 18:37

Hi,

I want to remove the "member for" snippet from the user profile page.

Customising the user profile layout as recommended here http://drupal.org/node/35728
seems fine, but I want to leave the user profile as it is minus the "member for" snippet.
So from where would I copy the user profile layout that I have already?
Then I could create a template.php and a user_profile.tpl.php file, copy this in and just remove the "member for" bit.

Thanks.

The location

JirkaRybka - July 23, 2007 - 20:56

I don't know much about copying and theming and so forth, but I once changed something about this item on user-profiles (just patching the original file for different wording - unclean but simple solution for me). It's located in the User module, i.e. modules/user/user.module.

That did the trick ...

looklively - July 24, 2007 - 09:19

Thanks, JirkaRybka .

It's a bit of a corner-cut that I was hoping to avoid.
But ... job done.

-------------------------
For anyone else ... I removed
{
$items['history'] = array('title' => t('Member for'),
'value' => format_interval(time() - $user->created),
'class' => 'member',
);

return array(t('History') => $items);
}

from approx line 450 of modules/user/user.module

------------------------

Cheers.

Don't do that!

looklively - July 24, 2007 - 09:40

Please ignore the above.
Doing this has knock-on effects, it removes editing options in the user profile.

Ho hum, back to the drawing board.

Can anyone help me here?

The site I am building is for an established organisation and including "member for" (ie member of the website for) would seem to indicate length of membership of the organisation.
This is then misleading.

Thanks.

What about .css ?

mblazke - August 20, 2007 - 14:56

I've simply added the following to my theme/style.css
div.profile dl dt.user-member, div.profile dl dd.user-member { display: none;}

Good

JirkaRybka - August 20, 2007 - 17:19

Good idea, although I think CSS is not recommended for this kind of use (CSS is for presentation, not content-handling). Still it should work, probably the easiest hack :-)

Nice one!

looklively - August 21, 2007 - 10:07

Hey mblazke!
Top hack ...
As JirkaRybka says above, not exactly 'by the book' but it works ...

Thanks, Buddy.

the css method didnt work

mortenson - November 10, 2008 - 18:50

the css method didnt work for me in D6

Subscribing. I have the

joachim - December 7, 2007 - 14:04

Subscribing.
I have the exact same requirements -- new website for an old organization, and indicating how long it is since a member signed up to the site is misleading.
I wonder if there's enough demand to request this be made an option in the user profile module?

override theme_user_profile

Campsoupster - November 12, 2007 - 23:36

There's a themable function in the user.module with the name theme_user_profile. Copy that into your template.php and change "theme" to "phptemplate" or the name of your custom theme. Then, you can remove the entire history section with a simple if statement:

was:

  foreach ($fields as $category => $items) {
      if (strlen($category) > 0) {
        $output .= '<h2 class="title">'. check_plain($category) .'</h2>';
      }
      $output .= '<dl>';
      foreach ($items as $item) {
        if (isset($item['title'])) {
          $output .= '<dt class="'. $item['class'] .'">'. $item['title'] .'</dt>';
        }
        $output .= '<dd class="'. $item['class'] .'">'. $item['value'] .'</dd>';
      }
      $output .= '</dl>';
  }

Now is:

  foreach ($fields as $category => $items) {
    if ($category != 'History') {
      if (strlen($category) > 0) {
        $output .= '<h2 class="title">'. check_plain($category) .'</h2>';
      }
      $output .= '<dl>';
      foreach ($items as $item) {
        if (isset($item['title'])) {
          $output .= '<dt class="'. $item['class'] .'">'. $item['title'] .'</dt>';
        }
        $output .= '<dd class="'. $item['class'] .'">'. $item['value'] .'</dd>';
      }
      $output .= '</dl>';
    }
  }

I think that this is a better approach then altering core module code, or just using css (as display: none will hurt your search engine rankings).

Calrity Please

Insane Fisher - December 6, 2007 - 00:07

Can you give a little clarity to these instructions? I am very new to Drupal and to editing code. There seems to be something missing from the instructions, but I can not place a finger on what.

I am the building. I am the tree. I am God, for God's in me.

Themable functions

JirkaRybka - December 6, 2007 - 22:06

Themable functions (for Drupal 5 at least) are like this:

- Copy/paste the (themable!) function from a module into your theme - to the file template.php (if your theme haven't one yet, create a new empty file with <?php line at the top).

- Change the name of the function (at the function foo(...) { line) appropriately. Do all edits on the copy of the function, located in your theme! (NOT the original in the module)

- Now the function in your theme is used by Drupal, instead of the original, so you can change it as You like, without really changing the Drupal core files. This is supposed to make things clean, appearance changes fixed inside the theme rather than modules, and save you problems if updating core to a newer version.

- But still, you should check whether the copied function is up-to-date with the new Drupal version if upgrading (so in my opinion, it's not as much of a win, as it might look like)

- Although this code-editing and copy/pasting thing is difficult and dangerous for a newbie, it's the Drupal way of doing things, so you're likely to receive this kind of advice nearly every time you ask... ;)

Good to know!

kriskd - December 8, 2007 - 03:21

Thanks for this bit of code.

Question -- what else come be customized while still using the foreach loop? For example, this snippet show how to change the word "history" to "member for", but you have to explicitly call that bit of code. What if I want to generate everything with the foreach loop, but tweak a few things like that? Can that be done and if so, how?

Suggestion

stephen.colson - January 23, 2008 - 22:18

As a possibility, rather than having if ($category != 'History'), keep it stock. Then before the foreach, put unset($fields['History']);

I18n version

mapiedra - August 4, 2008 - 10:35

I have been working on the customization of a Drupal installation for some users (each user will have his/her own Drupal file set and database). There was a problem, though, because the interface is displayed in Spanish by default (the user could set it up in English, German or other language).

The "History" section is still displayed when the "if" statement does not sort it out. This scenario occurs when the language of the "History" string does not match with the language of the interface (i.e. you look for "History" and it reads "Historial").

Even when a PHP "or" (||) statement could be defined for the most probable languages, there is a more elegant solution. It is possible to use the t() function (string translation) from the API instead of the hard-coded "History" string. For instance:

foreach ($fields as $category => $items) {
    if ($category != t('History')) {
      if (strlen($category) > 0) {
        $output .= '<h2 class="title">'. check_plain($category) .'</h2>';
      }
      $output .= '<dl>';
      foreach ($items as $item) {
        if (isset($item['title'])) {
          $output .= '<dt class="'. $item['class'] .'">'. $item['title'] .'</dt>';
        }
        $output .= '<dd class="'. $item['class'] .'">'. $item['value'] .'</dd>';
      }
      $output .= '</dl>';
    }
  }

Thanks!

Itangalo - November 22, 2008 - 11:02

Thanks to mapiedra and the rest who helped me with this theming issue!
I refer to this post in a short guide on how to use theme funktions, written in the Swedish group forum.

//Johan Falk, Sweden

There's a module that does

joachim - November 22, 2008 - 12:40

There's a module that does just this: http://drupal.org/project/myaccount_alter

 
 

Drupal is a registered trademark of Dries Buytaert.