2

I have a custom module that creates a search form and displays search results. We have a need where we want the title that displays in the browser tab to change depending on the search criteria. This particular search searches jobs that are available in specific specialties. I know you can use drupal_set_title() to change the title that gets displayed to the user in the H1 tag on the page, but what I am talking about is changing the title in the browser. The actual title tag for SEO purposes. So by default, the Browser tab title says "Job Search | My Site Here" ("My Site Here" is a place holder for the actual name of my site). When they perform a search we want the title to change to "{Specialty Name} Jobs | My Site Here". So for example if they search on the specialty "Cardiology", the browser title will be "Cardiology Jobs | My Site Here". I know there are custom modules to handle changing the page title dynamically, but those are for existing content types. This job search has been created completely from within a custom module, so ALL of the pages are dynamic. Is there a way to edit the browser page title independently of the drupal_set_title() function from within the custom module?

1

See this question and answer. In short, I think your might be looking for something like hook_preprocess_page().

function mymodule_preprocess_page(&$variables) {
  $variables['head_title'] = t("The new HTML title.");
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.