I'm looking to use the variable $title in my html.tpl.php file. How can I do this?

I would like to just write a bit of php like so:

<?php print $title ?>

So is a preprocess function needed? TPLNAME_preprocess_html() { ??? something like that?

I would like to reference this question here which got me thinking, what is the proper way?

Helpful Question That I Saw

2 Answers 2

// template.php
function THEMENAME_preprocess_html(&$vars) {
  $vars['title'] = 'my title';

// html.tpl.php
echo $title;


  • Would this also work for the current node being viewed?
    – TikaL13
    Sep 27, 2011 at 14:39
  • hook_preprocess_html called on all pages. If you edit vars only node view page - use hook_preprocess_node and template node.tpl.php
    – xandeadx
    Sep 27, 2011 at 14:58
  • What I am trying to do is pass the current nodes title to a variable within my html.tpl.php file. Does that make sense? Thanks again for your reply.
    – TikaL13
    Sep 27, 2011 at 18:03

If you are wanting $title to be the node title of the current page (if it is a node page), which you mentioned in a comment above, you can do this in your theme's template.php:

 * Override or insert variables into the html templates.
function THEMENAME_preprocess_html(&$vars) {
  if ($node = menu_get_object()) {
    $vars['title'] = check_plain($node->title);

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.