Use case:
- Adding some HTML markup to site name or slogan can be an easy way to make a site prettier. For example set the site name to "My very own site". This has the desired visual effect on the site name, but the page title contains the tags literally. It would be desirable to strip the site name (and slogan) of HTML tags before adding them to the page title

Solution:
- Edit includes/theme.inc and wrap a strip_tags() around the site name and slogan before adding them to $head_title. Patch attached. Note that maintenance.theme.inc may need similar adjustments...

CommentFileSizeAuthor
strip_tags_in_title.tar_.gz24.55 KBpeterdm

Comments

dddave’s picture

Status: Active » Needs review

Correcting status...

ligerbots’s picture

Just wanted to thank you for finding this problem. I recently changed my site to include a <span>, and just noticed that the page title was all wrong. I dropped the changed function into template.php and the title was repaired.
You saved me quite a headache.

dddave’s picture

Version: 7.4 » 8.x-dev

Whomever it might concern: Resetting against current head although I don't know if the new theme system still has this issue. If that's not the case please re-set against 7x-dev.

dddave’s picture

Whomever it might concern: Resetting against current head although I don't know if the new theme system still has this issue. If that's not the case please re-set against 7x-dev.

BarisW’s picture

Version: 8.x-dev » 7.x-dev

Seeing this code it seems this has been fixed in D8, so setting it back to D7.

<?php
  if (drupal_get_title()) {
    $head_title = array(
      'title' => strip_tags(drupal_get_title()),
      'name' => check_plain($site_config->get('name')),
    );
  }
  else {
    $head_title = array('name' => check_plain($site_config->get('name')));
    if ($site_config->get('slogan')) {
      $head_title['slogan'] = strip_tags(filter_xss_admin($site_config->get('slogan')));
    }
  }
?>

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.