Drupal uses the <h1>
tag in the title of the view. I want to change title's tag <h1>
to <h2>
.
5 Answers
hope this will help you..
function mymodule_views_pre_render(&$view) {
if ($view->name == 'view_name') {
// Here you can do any php you want to get the title you need for your view.
$view->build_info['title'] = "<h2>My custom title!</h2>";
}
or by views-view-unformatted--viewmachinename.tpl.php file
<?php if (!empty($title)): ?>
<h2><?php print $title; ?></h2>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
<div<?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"'; } ?>>
<?php print $row; ?>
</div>
<?php endforeach; ?>
-
Wouldn't first method just put
h2
inside originalh1
? +1 for .tpl.php but please check that first part, OK?– MołotCommented Nov 28, 2013 at 12:02 -
Good Observation actually that is not the correct answer, theming shold be from tpl end.should i edit the answer by removig the first option?, Commented Nov 28, 2013 at 12:06
-
You can change the title, as well as h1 to h2, using view title
You can trick this leaving empty the title view field and adding the title as a text on the header view area.
This can be done with a simple configuration supported at the views-fields area.
Click the title field you want to theme under the Fields area and configure the following in the pop-up,
Under the Rewrite results tab enable the option Rewrite the output of this field, here you will be having the replacement token for title configure it as
<h1>[title]</h1>
If you still need to strip all the other html tags in the title check the Strip HTML tags (This will strip all the html tags including the <h1>
tag you have configured above hence add the <h1>
tags in the Preserve certain tags )
-
This changes format of a title field of listed content, not the title of a view.– MołotCommented Nov 28, 2013 at 12:01
-
Apologies, I thought of changing the node-title field in views. Thanks Molot Commented Nov 28, 2013 at 12:33
You can find the <h1>
tag for the title in the page.tpl.php file of your theme.
If the path of your view is 'bike', you would use page--bike.tpl.php. If your path is 'bike/three_wheel' you could use page--bike-three_wheel.php.php.
- Copy the page.tpl.php file to a folder
- Rename the file (page--bike.tpl.php)
- Edit the file with your new tag (or another thing)
- Save the file
- Put the file in the same place of your page.tpl.php file
- Clean the cache
- Enjoy
Reference: