I have view that uses url args: parent term id and term id/ids, so the url structure is like page/%/%

Title pattern for this view is: %1(%2)

However I have few pages with multi tids as second argument, so generated title is strange (very long). I am trying to change this title programmatically:

function bip_title_alter_views_post_render(&$view, &$output, &$cache)  {

    if ($view->name == 'kategorie_artykulow' && $view->current_display == 'page_9')
        $args = explode(' ', $view->args[1]);
        if (sizeof($args) < 2) {
        $title_pattern = 'Archiwum Oświadczeń Majątkowych w %dr.';
        $term = taxonomy_term_load($args[0]);
        if (! $term) {
        $title = sprintf($title_pattern, $term->name);

function bip_title_alter_module_implements_alter(&$implementations, $hook) {
    if ($hook == 'views_post_render') {
        $group = $implementations['bip_title_alter'];
        $implementations['bip_title_alter'] = $group;

but title remains the same, I am sure that I am altering proper view.

Adding another display to view is not good option for me, because I have a lot existing urls and if I create another display with the same url structure and different args config always first display is handling request.


I changed my custom module weight in system table to 9999 and I still see that title is altered after my module hook :/ It's so annoying

  • Probably the only way is to alter title in template.php in this case
    – Codium
    Oct 10, 2012 at 17:39
  • 1
    If you're doing a drupal_set_title() early enough, then presumably something's overriding the title you've set. You could try printing out a backtrace from within drupal_set_title() and also print out the title passed in. This might show what's causing problems.
    – Andy
    Oct 10, 2012 at 17:49
  • @Andy I am doing this and I see that title is replace after my hook calling
    – Codium
    Oct 10, 2012 at 17:51
  • 1
    You can use the backtrace to identify what is replacing the title - and then hopefully either prevent it, change it, or find a way to set the title even later.
    – Andy
    Oct 10, 2012 at 18:03

3 Answers 3


I always use a hook_views_pre_view():

function mymodule_views_pre_view(&$view, &$display_id, &$args) {
  if ($view->name == "foo" && $view->current_display == "bar") {
    $view->display[$view->current_display]->display_options["title"] =
    $view->display[$view->current_display]->handler->options["title"] = "The New Title";

This should then funnel up to be pulled in as the page title, but I never use views directly as pages.

  • Thanks still not work, I see that title is altering by different hook that is called alter views_post_render. I should find other way to alter title
    – Codium
    Oct 10, 2012 at 16:55

Thanks to @Andy advice the solution is so simple.

Views set title after calling to views_pre_render and views_post_render: (views_plugin_display_page.inc)

  // And now render the view.
    $render = $this->view->render();

    // First execute the view so it's possible to get tokens for the title.
    // And the title, which is much easier.
    drupal_set_title(filter_xss_admin($this->view->get_title()), PASS_THROUGH);

If there is a get method there is a big chance that setter exists ;)

So calling:


inside hook (pre or post) do the job


I would use hook_views_pre_render and alter the views display title.

Refer to http://drupal.org/node/438370 as well.


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.