Add a custom head title to a filtered view page in Drupal

712 Views Asked by At

I have a site that filters the blogs by specific expeditions.

Currently, when I click on the blog related to that specific expedition it displays the head title (in browser window) as "| mysite". So all the filtered views have the same head title.

I would like to add a custom head title for each filtered view.

So, for example, I would like the blogs that have do with Expedition 1 to have a filtered view with the head title "Expedition 1 blogs | Mysite".

Does anyone have any suggestions?

3

There are 3 best solutions below

0
On

This question may be related to this one where the following solution was given:

In template.php:

function YOUR_THEME_preprocess_page(&$vars){
  // You can test if you're in your specific views of course
  $path = $_GET['q'];

  if (strpos($path,'YOUR_PATH_STRING') !== false) {
    drupal_set_title('YOUR_TITLE');
  }
}

I also saw the reference to the Page Title module that could suit you.

1
On

I suggest you do this :

for Views 3:

If you have a view and you want to be able to programmatically change the title of, you can do it by implementing hook_views_pre_render in your custom module:

<?php
/**
 * Implements hook_views_pre_view().
 */
function MODULENAME_views_pre_render($view) {
  if ($view->name == 'my_view_name') {
    if ($view->current_display == 'my_display_name') {
      $view->set_title('my new title');
    }
  }
}
?>

I hope it helps.

0
On

You can set views page title programmatically by using below hook in modules.

function MODULE_NAME_views_pre_view(&$view, &$display_id, &$args) { 

    if($view->name == 'VIEW_MACHINE_NAME'){
      $view->display[$view->current_display]->display_options["title"] =
      $view->display[$view->current_display]->handler->options["title"] =
      $view->human_name .' - '.$_GET['field_video_by_event_value'];
    }

}