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.
By BadDaddy on
To call page specific html.tpl.php document for Drupal 7, enter this code in the template.php document:
function THEMENAME_preprocess_html (&$vars) {
if (module_exists('path')) {
$alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
if ($alias != $_GET['q']) {
$template_filename = 'html';
foreach (explode('/', $alias) as $path_part) {
$template_filename = $template_filename . '__' . $path_part;
$vars['theme_hook_suggestions'][] = $template_filename;
}
}
}
}
- Duplicate the 'html.tpl.php' document and name it 'html--PAGENAME.tpl.php' (this example would be 'html--hook.tpl.php'), enter custom code and upload it to the server if working online
- With safe URL's turned on, create a page ('hook' for instance). This would be the address 'http://www.example.com/hook'
- Navigate to: 'Administration » Configuration » Development' and click 'Clear all caches'
- Navigate to your page ('hook' in this example) and refresh the page
Comments
If my url alias is
If my url alias is hook-example, my html template would be 'html--hook-example.tpl.php', right?
Thanks for your help
I've been looking for a way
I've been looking for a way to do this for a while. Your solution is not only simple, but also works perfectly. Thank you!
Worked perfect for me, Thank YOU!!
It Worked perfect for me, Thank YOU!!
Cannot get this to work
My problem is I can't simply add this code. I get:
So, I am trying placing it in preprocess_html function like this...
Please pardon me, but I do not know PHP or Drupal development.
The template.php file is in the original Bartik theme folder too.. I can't add one to my subtheme folder because I Get the same error
Is there some place in particular I need to place this code?
Edit: Never mind, I got it. I'm always learning. I was not using the name of my sub theme!
Works great thank you! Now, would it be more Drupally to setup second template.php file in my subtheme folder with this modification in there instead of modifying the original? This method seems to work. Are there issues with it?
Thanks
It worked on my first try, that usually never happens!
Worked smoothly
Thanks for posting this. This worked smoothly for me.
That's not even necessary
That's not even necessary actually.
If you check the content of the $vars, you'll see that there is a number of suggestions already, just copy html.tpl.php in your base theme templates folder (create one if there is none) and rename it with the most appropriate suggestion, that tpl will be used instead.
Delphine is right. I was able
Delphine is right. I was able to override html.tpl.php in a Drupal 7.43 install for specific nodes with to following pattern:
html--node__1529.tpl.php
:~: Senior Drupal Site Builder
How would you do it for login
How would you do it for login page? Thanks
See Customizing and
See Customizing and Overriding User Login page, Register, and Password Reset in Drupal 6 and 7
:~: Senior Drupal Site Builder