I need to change the title head of the pages in Drupal 7 by path. NOt to all content type. I need to change the title head to a specific page generated with views.

For example, I have a site http://www.mysite.com

<title>My favorite website </title>

I need the for pages:


<title> My test today </title>


<title> My examples for share </title>


  • I'm not sure what you mean by "change the title head to a specific node." Could you clarify please? Two common modules that help in this area are drupal.org/project/pathauto and drupal.org/project/auto_nodetitle You might check them out and if they don't work, explain how your use case is different than the ones these common modules handle. Mar 5, 2012 at 15:48
  • I refer to the "title head" that appears in the meta tags. The title that is shown in the tabs of the browser. Thanks.
    – cabita
    Mar 5, 2012 at 16:01

2 Answers 2


Here is how I did it in Drupal 7.

In template.php:

function YOUR_THEME_preprocess_page(&$vars){
  $path = $_GET['q'];

  if (strpos($path,'YOUR_PATH_STRING') !== false) {

For example, if your path was yoursite.com/boogabooga, then you would set 'YOUR_PATH_STRING' to 'boogabooga' and 'YOUR_TITLE' to whatever you want the page title to be.

  • this doesn't work for hook_preprocess_user_profile May 25, 2017 at 15:33
  • What could be the string to write for targeting the <front> page?
    – Mars
    Aug 3, 2018 at 21:27

It sounds for your limited set of pages maybe implement THEME_preprocess_html() and examine the url path and override $vars['head_title']. See this blog post as an example: How to set custom page title in Drupal 7

If you have some patterns for the head title try Page Title

  • I saw the post and I have a question, if I want to assign a "head title" to the specific paths. Not to all paths will have the same title. For example I need mysite.com/test the <title> is "My tests" and I have other page mysite.com/examples I need that <title> "Examples for share". Is this code useful for this purpose? I have updated my post.
    – cabita
    Mar 6, 2012 at 13:23
  • @cabita Tenken's post covers your use case. Besides what he already mentioned you can also use the Meta tags module. All 3 options allow you to set the head title for the specific node pages you want without touching the rest.
    – Madis
    Mar 6, 2012 at 23:03
  • I tried with meta tags and allow change the title head for specific pages but no for specific pages generated by views. I will update my question again. I'm sorry.
    – cabita
    Mar 6, 2012 at 23:17
  • @cabita Did you also try Page Title? It at least claims to have views integration. If this doesn't work out either you could just go ahead and do it in the code (it's easy to restrict changes to specific pages only by using $_GET['q'] or arg() to check the path).
    – Madis
    Mar 6, 2012 at 23:33
  • I did in the code. You are right, it's easy to restrict changes to specific pages only by using $_GET['q'] or arg().
    – cabita
    Mar 7, 2012 at 11:15

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.