Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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);
...
- 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 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);
}
Comment | File | Size | Author |
---|---|---|---|
#17 | panels_everywhere-n1082010-16-d6.patch | 2.65 KB | DamienMcKenna |
#14 | panels_everywhere-n1082010-14-d7.patch | 4.38 KB | DamienMcKenna |
Comments
Comment #1
Kars-T CreditAttribution: Kars-T commentedHi
I like the idea. Maybe provide a patch?
Comment #2
mattyoung CreditAttribution: mattyoung commentedpatch 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:
to:
Comment #3
Kars-T CreditAttribution: Kars-T commentedGreat! :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.
Comment #4
Letharion CreditAttribution: Letharion commentedComment #5
Letharion CreditAttribution: Letharion commentedWhat are you viewing to reproduce this problem? I can't see it unless I unset($page_title) before this code runs.
Comment #6
Kars-T CreditAttribution: Kars-T commentedThis 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.
Comment #7
Letharion CreditAttribution: Letharion commentedThat'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.
Comment #8
Kars-T CreditAttribution: Kars-T commentedYou 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?
Comment #9
mattyoung CreditAttribution: mattyoung commented>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:
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 | ".
Comment #10
DamienMcKennaI'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.
Comment #11
DamienMcKennaRerolled for D7. Needs some testing and possibly additional tweaking.
Comment #12
DamienMcKennaImproves the logic, per #9;
Comment #13
DamienMcKennaComment #14
DamienMcKennaRerolled, with some small improvements.
Comment #15
DamienMcKennaCommitted to D7.
Comment #17
DamienMcKennaSome small improvements for the D6 codebase to match the D7 codebase.
Comment #18
DamienMcKennaCommitted.