Right now, I have it set so that the account page and profile page are the same, not separate. I have a field in my profile called Real Name:
How can I make "Real Name" the heading of the account page and NOT the username? I originally wanted to keep the account pages and profiles separate but I honestly couldn't find a way to access other user's profile pages even while logged in as admin. I couldn't figure out the url... In any case, I suspect the user name would have been the main heading on both pages anyway.....so, how can I manipulate the template to get it to do what I want?
I think it has to do with this code:
print $title;
in the user item tpl, but I don't know if I can theme these profile fields and do they theme like CCK fields did in D6? I know how to manipulate fields using D6 and CCK....not sure about d7 and the profile fields for this module....
Becky
Comment | File | Size | Author |
---|---|---|---|
#34 | before-and-after.png | 244.08 KB | bisonbleu |
#13 | profile2_username_title.info.txt | 236 bytes | deanflory |
#12 | profile2_username_title.module.txt | 690 bytes | deanflory |
Comments
Comment #1
hedley CreditAttribution: hedley commentedTo remove the profile title (by default this title is "main profile".), you can copy 'user-profile.tpl.php' from /modules/user into your theme directory, then add this to the file:
BEFORE
Slightly confusing as there is a 'profile.tpl.php' in the profile2 module folder which you may assume you have to edit to remove this title. There may even be a cleaner way to accomplish this with a template preprocess function.
Comment #2
hedley CreditAttribution: hedley commentedTo change the content title (defaults to the username) you can use this snippet in a custom module:
Change 'myfield' to whatever your profile2 field is. and MYMODULE to the name of your module. You may also need to change $profile2['main'] if you have created a custom profile type.
The thing you have to remember here is that the $title is built from the menu system, so you can't use a preprocess_page to edit it. The other way to do this would be to put some similar code into page.tpl.php
Comment #3
Syd Barrett CreditAttribution: Syd Barrett commentedShould this go on page.tpl.php?
Comment #4
hoff331 CreditAttribution: hoff331 commentedI have the "profile2 pages" module turned off. When you go to a user profile, the username is the page title.
I have tried using this code and it does not work... I set 'main' to the machine name of my profile type and 'field_myfield' to the machine name of my profile specific field.
Does the module we create need specific profile2 dependencies set in the .info file?
Comment #5
trevorleenc CreditAttribution: trevorleenc commentedI had a heck of a time today trying to get the code here, and the code from a post on Stack Exchange...
anyway...this tinkered and dinkered combo of code from both here works for me, hope this helps save someone some time.
ref: http://drupal.stackexchange.com/questions/13283/change-page-title-on-use...
Comment #6
elpino CreditAttribution: elpino commentedI found this documentation page https://drupal.org/node/1392716 explaining how to accomplish this using Rules.
It gives the following code so that you can import the rule, and then adjust the conditions and actions to suit your own profiles
However it's not working for me for some reason.
Comment #7
museumboy CreditAttribution: museumboy commentedI tried to use number 5 as a template.php hook and it works if you flush the cache. However eventually the names revert back to the normal username. Is that why this needs to be a module and cannot be a template.php hook?
Comment #8
bisonbleu CreditAttribution: bisonbleu commentedNOTE - I'm using the latest dev version (7.x-1.3+4-dev).
I'm displaying profiles on separate pages. Unfortunately,
[profile2:field-member-first-name] [profile2:field-member-last-name]
. But when I switch to English, it's back to the default label Member Profile.The strange part is that when I
print_r($profile2);
in profile2.tpl.php, the label is fine even when I'm in the English UI.Comment #9
bisonbleu CreditAttribution: bisonbleu commentedComment #10
bisonbleu CreditAttribution: bisonbleu commentedIn the end the following works perfectly for my use-case. Create a simple module, paste this function into the .module file, change the placeholder snippets (my_module, field_first_name, field_last_name ) and your good to go.
Don't forget to delete the php end tag (?>) of the .module file!
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedThe solution in #10 works perfectly. Thanks.
Comment #12
deanflory CreditAttribution: deanflory commentedThanks bisonbleu, #10 worked flawlessly.
My site uses first, middle and last names and I wanted to present all three. Here's the code I used (downloadable files attached):
Module folder name:
profile2_username_title
profile2_username_title.info
profile2_username_title.module
Comment #13
deanflory CreditAttribution: deanflory commentedAnd the .info file:
(just remove the .txt off the end)
Comment #14
deanflory CreditAttribution: deanflory commentedIt would be great if this were integrated into the profile2 module as a submodule and allow tokens to be inserted and arranged by users on an admin panel since I imagine most every user of the profile2 module would utilize this feature.
Comment #15
qlumbus CreditAttribution: qlumbus commentedThanks. This is exactly what I am looking for.
Unfortunately I receive the following error message when enabling the module:
Comment #16
qlumbus CreditAttribution: qlumbus commentedThe Real Name module does the trick as well: https://www.drupal.org/project/realname
Comment #17
bisonbleu CreditAttribution: bisonbleu commented@qlumbus,
Make sure that the machine names for First name and Last name are set to field_first_name and field_last_name respectively. You can see the machine names in the Manage fields tab of your profile2 type.
Comment #18
ret5 CreditAttribution: ret5 commentedFyi - Was able to change the Profile2 Page Title using Rules.
1. Create Rule on Event, "When Profile is Viewed"
2. Set Action "Set A Data Value" where profile2:user:your-profile-type-name:label
3. Set Data Value to use whatever token, url, or text you like.
Hopefully that helps out.
Comment #19
jigish.addweb CreditAttribution: jigish.addweb at AddWeb Solution Pvt. Ltd. commentedIf you want to change page title, you can change directly using Page Title module, pattern replacement.
If you want to change page header, then you need to make small stuff of customization for same. Please find below code snippet for same. This code will be in your theme template file.
Let me know in case of any further query/concern.
Thanks!
Comment #20
Benoit63 CreditAttribution: Benoit63 commentedI spent many time to find a good solution to this problem! The differents issues didn't satisfying me, certainly because i'm not a good drupal themer or developper... The solutions proposed with rules module didn't work for me too, because the modification of title occurs only after a page reload (not on first load), i don't understand why.
Anyway, i finally found a solution adapted in my case (separate page, in particular) thanks to the rules bonus pack module, which allow to create new rules.
Here is my rule :
{ "rules_title_profile_modification" : {
"LABEL" : "Title profile modification",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "profile" ],
"REQUIRES" : [ "rules", "rb_misc", "rb_theme", "profile2" ],
"ON" : { "profile2_view" : [] },
"DO" : [
{ "rb_misc_action_set_title" : { "page_title" : "[profile2:field-name] [profile2:field-fname]" } },
{ "rb_theme_action_set_head_title" : { "head_title" : "[profile2:field-name] [profile2:field-fname]" } }
]
}
}
The rule modify the page title, but also head title.
Hope this could help.
Comment #21
blacklime CreditAttribution: blacklime commentedI've found a simple solution to this for anyone interested. It can be difficult to print profile2 fields anywhere other than user-profile.tpl.php - so what you can do to set / change your page title pattern for a user profile (i.e. If you want your title to be something like "Profile2 Field | Site Name"). So I did the following:
Example:
Title Tag Starts Here
print $profile['profile_type']->field_name['und'][0]['value']
Title Tag Ends Here
Conclusion:
This may not be the most "valid" way of doing it, but after trying a number of different solutions posted on various forums, I made my own solution. It's quick / dirty, but it works like a charm.
Tweet @blacklimemedia w/ any questions or comments.
Comment #22
luxpir CreditAttribution: luxpir as a volunteer commentedFor anyone just trying to hide the title on the user page, profile2 or otherwise, I added the following to the template.php file in my theme directory:
I actually had to add the snippet from
$arg
onwards (excluding the final brace, it was already there - added extra whitespace here for clarity - also ignore the php tags, I only added those to give the snippet glorious technicolor) into the existing preprocess_page section, not realising that you couldn't call it twice (drush told me about this error when I cleared the cache). This is cobbled together from a few SE and d.o comments, some of which had syntax errors (additional parentheses) but it did the trick in the end.Prior to this I tried using Rules, which worked but changed usernames in the DB which I did not realise it would do, and also the realname module suggested here, which did the same. In my case I wanted users to keep their chosen usernames, just didn't want to display them on public profiles (as contact information revealed to members only).
Hope that helps.
Comment #23
NikLP CreditAttribution: NikLP as a volunteer commentedWith regards to the previous comment, I suspect that
might need to be replaced with
as the templates often use
isset($var)
to check whether to render the variable or not. I'm open to correction though.Comment #24
luxpir CreditAttribution: luxpir as a volunteer commentedWas some discussion of that at SE where part of the snippet came from. Might be theme dependent? In any case it works as it is for now. Will revisit if problems arise!
Comment #25
tory-w CreditAttribution: tory-w as a volunteer commented#18 worked perfectly.... I have it set up to show the FIRSTNAME and LASTNAMEINITIAL on both the Account/User and Profile 2 pages.
Comment #26
joachim CreditAttribution: joachim commentedThere's an actual Real Name module, which may do what you want.
Comment #27
nategasser CreditAttribution: nategasser commentedI like #10 but had to make a small change:
if (!isset($build['empty']) && ($build['#bundle'] == 'public_info')) {
because I have more than one profile type, and it throws errors if you look for fields in the wrong profile type.
Note: "public_info" is the machine name of the profile I wanted to use fields from.
Comment #28
rami.sedhom CreditAttribution: rami.sedhom commentedIt works very nice using Rules as per comment #18
Comment #29
deanflory CreditAttribution: deanflory as a volunteer commentedI've just found that the method in #10, 12, 13 above works to make the fields you want render as the page title on the profile2 pages, BUT if you also create a View that uses the Rendered Entity method to display a user's profile as a field, it will change the page title of any page that displays that View as a block.
Comment #30
bisonbleu CreditAttribution: bisonbleu commented@deanflory, you can achieve what you want by limiting/reducing the scope of the hook_form_alter.
I don't know if this is the best way, but it's one way. The new outer if checks if the body tag of the page contains a class associated to a profile. In my case, that is
page-profile-membership
. If the profile class is found, then the context is a profile page. If the profile class is NOT found, then the context is different.Comment #31
deanflory CreditAttribution: deanflory as a volunteer commentedI've tried your code in #30 bisonbleu and found it didn't work to change the profile2's page title on my site. Also, here's an error I received:
Here's the exact .module code I used:
The class "page-profile-public" exists.
Comment #32
bisonbleu CreditAttribution: bisonbleu commentedAs mentioned, my code is specific to my website i.e. does not completely apply to yours or others.
To be more specific, the class
page-profile-membership
exists on my website because the machine name of my Profile2 profile is membership. In other words, the class name is created as follows:page-profile-[the name of your profile]
.The reason why in your case it's
page-profile-public
is because the machine name of your Profile2 profile is public.If someone has a Profile2 profile named experts, then the class name to look for will be
page-profile-experts
.Comment #33
deanflory CreditAttribution: deanflory as a volunteer commentedUh, yes, I understood all of the class names and altered my code accordingly by changing it to page-profile-public as that is the class being used, but it still does not work. Thanks anyway.
Comment #34
bisonbleu CreditAttribution: bisonbleu commentedHum... Couple of things...
Here's what I see @ en/profile-membership (my profile)
<body class="html not-front logged-in one-sidebar sidebar-second page-profile-membership page-profile-membership- page-profile-membership-1 i18n-en lang-en section-profile-membership" >
and this @ en/profile-membership/13948 (another user's profile)
<body class="html not-front logged-in one-sidebar sidebar-second page-profile-membership page-profile-membership- page-profile-membership-13948 i18n-en lang-en section-profile-membership" >
What does your
<body>
tag look like?Also, I created a Profile2 block (Profiles) view and, like you said, saw that the Our history page title was overridden. Then I added
if (strpos ($classes, 'page-profile-membership')) {...}
and as you can see in the capture, the page title is back.So I don't see why it would not work.
Comment #35
sam-elayyoub CreditAttribution: sam-elayyoub as a volunteer commentedTry to use any module and add one of the codes below (prefer to start your own module and name it something like user_profile_title or so which you can add more codes later for that page)
1- depending on the path/url
2- depending on your user first name and last name
for me I prefer to use always the first one, because it can be changed later through autopath and change auto by changing the url plus no need to load the user profile multiple times
Comment #36
eworwa CreditAttribution: eworwa as a volunteer commentedI can confirm that the realname module (https://www.drupal.org/project/realname) worked for me. I'm using Drupal 8.3.7 and installed realname 8.x-1.0-rc1. I'm not sure how this worked in the past, but now I can confirm that keeps the user name as it. I'm not using the profile module thou.
Update: I spoke too soon. This module is not working properly due to a Drupal Core issue (https://www.drupal.org/node/2629286). Looking in the issue queue someone mentioned this other module https://www.drupal.org/project/name, I haven't tried yet but it looks like a good option. If it doesn't work, I will try the Rules approach.
Comment #37
capysara CreditAttribution: capysara commentedThanks, everyone!
I needed to change the title using the profile on a separate page. I used a variation of #10 and it worked great, but I needed to update the title on the /edit page, too, so I also used hook_form_FORM_ID_alter().
Comment #38
RickJ CreditAttribution: RickJ commentedPlease look at the experimental patch in #3029027: Allow entry and display of profile title.
Is that of any use in relation to issues here?
Comment #39
Richard15 CreditAttribution: Richard15 commented#19 is the only one worked for me.
The same function ("preprocess page") doesn't print [title] at all, so I couldn't modify it
In template.php it works!
Thanks!