Hi there,
Currently the user/register user/password and user/login all show the same page title (the title at the top of the browser shows 'User Account | sitename'). I want to change this as the below:
user/register => Create account | Sitename
user/password => Forgot password | Sitename
user/login => Log in | Sitename
I was able to find the below code and tried putting it into template.php under function theme_preprocess_page(&$vars) but it didn't work.
Then I tried in a custom module under hook_init function but it didn't work.
if (arg(0) == 'user' && arg(1) == 'register') {
drupal_set_title(t('Create new account'));
} elseif (arg(0) == 'user' && arg(1) == 'password') {
drupal_set_title(t('Request new password'));
} elseif (arg(0) == 'user' && arg(1) == 'login') {
drupal_set_title(t('Log in'));
} elseif (arg(0) == 'user' && arg(1) == '') {
drupal_set_title(t('Log in'));
}I'm trying to find the best way (performance wise) to correctly change the page title on these pages plus maybe other pages.
Would anyone be able to assist with this?
Thank you!
Comments
I would use the
I would use the hook_menu_alter:
http://api.drupal.org/api/function/hook_menu_alter/6
<?phpfunction hook_menu_alter(&$items) {
$items['user/register']['title'] = 'your title here';
}
?>
then clear the cache to rebuild the menus.
Ionut Alexuc Drupal Developer
CodePixels
The code above didn't seem to
The code above didn't seem to change the page title shown at the top of the browser. (I placed it into my custom module and cleared cache.)
I am getting emails with quotes of $50-$100. I hope this won't be that expensive x_x
Thank you
Are you inserting it with
Are you inserting it with hook_menu_alter or changing "hook" to be the name of your custom module?
Hi, Here is the awesome way
Hi,
Here is the awesome way to achieve this, use this module
http://drupal.org/project/nodewords_pagetitle
This is surely gonna work without inserting any code file.
Cheers
Sagar
Need help ?
Reach me on skype : sag_13684
Share your Posts, Url, Sites
www.sociopost.com
Need Varnish, Memcache, Apc, Solr, Drush and Drupal friendly host ?
http://drupion.com
Use hook_form_alter
I'm not sure that the module Nodewords Page Title work for it, but if you wish to place it in your module, you need to use hook_form_alter:
function your_module_form_alter(&$form, $form_state, $form_id) {if ($form_id == 'user_register') {
drupal_set_title(t('Create new account'));
}
elseif ($form_id == 'user_pass') {
drupal_set_title(t('Request new password'));
}
elseif ($form_id == 'user_login') {
drupal_set_title(t('Log in'));
}
}
This also serves
function your_module_form_alter(&$form, $form_state, $form_id) {if (arg(0) == 'user' && arg(1) == 'register') {
drupal_set_title(t('Create new account'));
}
elseif (arg(0) == 'user' && arg(1) == 'password') {
drupal_set_title(t('Request new password'));
}
elseif (arg(0) == 'user' && arg(1) == 'login') {
drupal_set_title(t('Log in'));
}
elseif (arg(0) == 'user' && arg(1) == '') {
drupal_set_title(t('Log in'));
}
}
Hope that helps you
Juan
Thanks Juan
This is exactly what I was looking for. Hopefully this helped yaz085 bc $50-$100 is too steep for these few lines of code.
sweet
Thanks a million.
D7 has a different form ID
Note that in D7, the User Registration Form ID is :
user_register_form.Modify the code accordingly. e.g.
if ($form_id == 'user_register_form') {drupal_set_title(t('Create new account'));
}
Perfect solve
Perfect solve, esp. if you already modifying the form via hook_form_alter.
#1251188: Fix page title for
#1251188: Set unique titles for user/register, user/password, and user/login menu items Raised it as a bug
Some of my Drupal sites:
Simple to achieve
Use page tpl php file. Rename to either page-user-password.tpl.php or page-user-pass.tpl.php depending on your theme, then remove
<?php print $head_title; ?>and insert your own title.Do the same for register pages by creating and modifying page-user-register.tpl.php
Sometimes there's an easy way out... :)
An Alternate Solution
I've solved this in D7 by using the Simple Page Module. Simple fix and works perfectly (at least for me).
http://drupal.org/project/simple_page_title
Hope that helps!
change title
hi, that changes the title in the source code, but not on the actual page
change page title
okay , I changed it in page.tpl.php probably not the best way to do it but it works
/
/