In the page--front.tpl.php template, I have the following code for site logo.

<img src="<?php print $logo ?>" alt="example.com logo" title="<?php print $site_name_and_slogan ?>" id="logo" />

Where is the title set in Drupal 7? Right now the title is showing blank in the production site.

  • So I checked the site information in the configuration/system page & system info and sure enough the site name and slogan values are filled in. However in the template and then the production site, the title value is blank why so? – sd100 Jan 10 '19 at 3:56
  • Is that variable a custom one? That could be why the title attribute is blank. Check the themes template.php file. – Kevin Jan 10 '19 at 4:11
  • I got this in template.php file: $variables['site_name_and_slogan'] = $site_name_text . ' ' . $slogan_text; – sd100 Jan 10 '19 at 4:14
  • Sounds like the variables aren’t populated correctly. – Kevin Jan 10 '19 at 4:28
  • Hmm ok also when I hover the cursor over the logo in desktop view, a blank popup comes up. Shouldn't it show the value for "Alt=" ? Should I even have title setup for img src html anymore? – sd100 Jan 10 '19 at 4:30

In your active theme's template.php, check template_preprocess_page() function and add following lines:

$site_name = variable_get('site_name');
$site_slogan = variable_get('site_slogan');
$variables['site_name_and_slogan'] = $site_name . ' ' . $site_slogan;

Assuming that you have used $variables as argument in template_preprocess_page() function.

Now $site_name_and_slogan can be used in page tpl files.

If you have not implemented template_preprocess_page() function, then replace template word with your theme name and add the function as mentioned below:

function THEMENAME_preprocess_page(&$variables){
  $site_name = variable_get('site_name');
  $site_slogan = variable_get('site_slogan');
  $variables['site_name_and_slogan'] = $site_name . ' ' . $site_slogan;
  • Ok I shall try. Thanks so much.. the active theme function is in a file or drupal setting? – sd100 Jan 10 '19 at 7:04
  • Also In Appearance section of the site's them there is a "Toggle Display" section. In it "Site Name" & "Site Slogan" are unchecked. Could this cause a problem? – sd100 Jan 10 '19 at 7:08
  • Checkboxes in appearance will not cause any problem with above implementation. Please check updated answer. – Vishal Patil Jan 10 '19 at 9:33

Have u tried these?

    <?php print $site_name; ?>
    <?php print $site_slogan; ?>

You can use it as

    <img src="<?php print $logo ?>" alt="example.com logo" title="<?php echo $site_name.$site_slogan; ?>" id="logo" />
  • I'll try for sure and revert back here. – sd100 Jan 10 '19 at 5:13
  • Ok it now sets the title to be site_slogan doesn't work. – sd100 Jan 10 '19 at 5:20
  • Sorry i had missed the $ symbol. Please check now – RK251 Jan 10 '19 at 5:28
  • Thanks but the result is a blank. It didn't work. – sd100 Jan 10 '19 at 5:30
  • is this a custom theme? if yes, need to see your template.php file – RK251 Jan 10 '19 at 5:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.