3

When user search Drupal 7 site, output page's title becomes: "Search | example.com"

But i want to make page title as: "Search: keyword1 keyword2 .. | example.com"

I installed "Page Title" module but i couldn't change it by it. Is there a module to convert page title regarding to this?

Thank you very much

4 Answers 4

4
  1. Install and enablde Page manager and Panels.
  2. Go to admin/structure/pages, on the line "search-node", click enable, then edit.
  3. Add new variant -> Create variant -> Choose any suitable layout -> Continue twice.
  4. On the final page in the Wizard, expand "Substitutions". You should see two keywords in there, copy "%keywords:raw" to the empty "Title" field above
  5. Below the keywords, click a cog in any suitable region, in the popup click Widgets, and select "Search form".
  6. Repeat step 6 for "Search results".
  7. Click "Create variant", followed by "Update and save".

Take variations for choosen layout into account, and your configuration should now look something like this

Panels search configuration

3
  • Thank you very much for detailed answer, i made the steps :) But the node title changed. Can't i change page title? I didn't see "search form" in Page Title module's content type column.
    – trante
    Commented Jan 9, 2012 at 18:50
  • I believe some definitions are in order. I see no reasonable way this could case any node-title to have changed, so please define more precisely what titles you speak of.
    – Letharion
    Commented Jan 9, 2012 at 18:53
  • Regarding to drupal.org/files/images/page-title.png with "page title" i mean the title of page in web browser. (i need this because search motor results show the pages without keywords)
    – trante
    Commented Jan 9, 2012 at 18:59
1

The module "pageTitle" can infact be used for the just named purpose.

After installing and enabling the module you go to the pageTitle configuration page. Here you can define default patterns, but you can also check the box "show field" for the desired content type, taxonomy or whatever. If a basic page is what you have chosen to show this field on, you just go to a node of that type. Added to the vertical tabs at the bottom of the page can now a new tab be found called "Page title setting". This is where you can set the pageTitle that appears in the browser tab and search results.

1

In Drupal 7, you can do this in your theme's template.php :

function MYTHEME_process_page(&$variables) {        

    if (arg(0) == 'search' ) {
        $keys = arg(2);
        if (!$keys) $keys = $_REQUEST['keys'];
        if ($keys) $variables['title'] = 'Search for "'.$keys.'"';      
    }

}

I dont know where your " Search | example.com" title comes from .. but this will probably remove that.

2$c, *-pike

1

In Drupal 7, you can do this in your theme's template.php :

function hook_preprocess_search_result(&$variables) {
  $node_title = $variables ['title'] ;
  .
  .
  .
  $variables['title'] = $title;
}
1
  • Wrong solution. In hook_preprocess_search_result is not a 'title' item in $variables.
    – Incredible
    Commented Sep 14, 2016 at 11:00

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.