The "head_title" page variable is created in panels_everywhere_page_preprocess_elements():

function panels_everywhere_theme_registry_alter($registry) {
...
  // @todo add a settings form to control the following parts of this:
  // separator
  // use site name in title
  // use slogan in title
  // Construct page title

  $head_title = array();
  $page_title = drupal_get_title();
  if ($page_title) {
    $head_title[] = strip_tags($page_title);
  }

  if (variable_get('panels_everywhere_head_title_include_name', TRUE)) {
    $head_title[] = strip_tags(variable_get('site_name', 'Drupal'));
  }

  if (!$page_title && variable_get('panels_everywhere_head_title_include_slogan', TRUE)) {
    $head_title[] = strip_tags(variable_get('site_slogan', ''));
  }

  $variables['head_title']        = implode(variable_get('panels_everywhere_head_title_separator', ' | '), $head_title);
...
  1. There is a little bug: if there is no slogan, the title ends up being "My site name | ", it should just be "My site name".
  2. I suggest moving this to a theme hook so that we can just override that hook to make customization (then there is no need to provide settings form as the todo comment suggest). Right now, to customize, we need to add code in our own page preprocess function and erase what panels_everywhere has done and re-do over.

This can be simplified to:

function panels_everywhere_theme_registry_alter($registry) {
...
  $variables['head_title']        = theme('head_title');
...
}


function theme_head_title() {
  $head_title = array();
  $page_title = drupal_get_title();
  if ($page_title) {
    $head_title[] = strip_tags($page_title);
  }

  $head_title[] = strip_tags(variable_get('site_name', 'Drupal'));

  if (!$page_title && $slogan = variable_get('site_slogan', FALSE)) {
    $head_title[] = strip_tags($slogan);
  }

  return implode(' | ', $head_title);
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Kars-T’s picture

Hi

I like the idea. Maybe provide a patch?

mattyoung’s picture

Version: 6.x-1.1 » 6.x-1.x-dev
FileSize
2.63 KB

patch attached. move head_title code to "head_title" theme hook

add one small change so there is no dangling " | " when slogan is not set.

was:

  if (!$page_title && variable_get('panels_everywhere_head_title_include_slogan', TRUE)) {
    $head_title[] = strip_tags(variable_get('site_slogan', ''));
  }

to:

  if (!$page_title && variable_get('panels_everywhere_head_title_include_slogan', TRUE) && variable_get('site_slogan', FALSE)) {
    $head_title[] = strip_tags(variable_get('site_slogan', ''));
  }
Kars-T’s picture

Status: Active » Reviewed & tested by the community

Great! :D

I did add the patch and tested it on one of our projects. I say it is running fine and is quiet simple. More or less copy / paste so no problems should appear.

But one thing to mention: Usually theme_something() funtions go to the main module. theme.inc seems nice but still wouldn't be my first choice. So let the maintainer decide.

Letharion’s picture

Assigned: Unassigned » Letharion
Letharion’s picture

What are you viewing to reproduce this problem? I can't see it unless I unset($page_title) before this code runs.

Kars-T’s picture

This is not really a bug but a feature request. It simply moves the title into a theming function which makes it easier for us to change.

Letharion’s picture

That's true, being able to change the head_title is useful in itself. I was just wondering that was triggering the bug mentioned in #1.

Kars-T’s picture

You mean this line?

"# There is a little bug: if there is no slogan, the title ends up being "My site name | ", it should just be "My site name"."

I think he is talking about PHP implode(). But afaik it won't put a | if there is only one element in the array?

mattyoung’s picture

>I think he is talking about PHP implode(). But afaik it won't put a | if there is only one element in the array?

The problem is not with implode. As I showed in #2, it's with:

  if (!$page_title && variable_get('panels_everywhere_head_title_include_slogan', TRUE)) {
    $head_title[] = strip_tags(variable_get('site_slogan', ''));
  }

When the page title is not set like in the front page, this adds the site_slogan to $head_title. But if your site_slogan is not set, it still adds '' (empty string). So when $head_title is imploded, the result is "Site name | ".

DamienMcKenna’s picture

I'm personally half-tempted to scrap the page title functionality entirely.. but for now I think making this a little more readily customizable may be sufficient.

DamienMcKenna’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Reviewed & tested by the community » Needs review
FileSize
4.26 KB

Rerolled for D7. Needs some testing and possibly additional tweaking.

DamienMcKenna’s picture

FileSize
4.37 KB

Improves the logic, per #9;

DamienMcKenna’s picture

Assigned: Letharion » Unassigned
DamienMcKenna’s picture

Issue tags: +SprintWeekend2015
FileSize
4.38 KB

Rerolled, with some small improvements.

DamienMcKenna’s picture

Status: Needs review » Fixed

Committed to D7.

  • DamienMcKenna committed 6503eff on 7.x-1.x
    Issue #1082010 by DamienMcKenna, mattyoung: Make head title controllable...
DamienMcKenna’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
Status: Fixed » Needs review
FileSize
2.65 KB

Some small improvements for the D6 codebase to match the D7 codebase.

DamienMcKenna’s picture

Status: Needs review » Fixed

Committed.

  • DamienMcKenna committed 4c1dce0 on
    Issue #1082010 by DamienMcKenna, mattyoung: Make head title controllable...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.