4

Drupal uses the <h1> tag in the title of the view. I want to change title's tag <h1> to <h2>.

1

5 Answers 5

2

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; ?>
3
  • Wouldn't first method just put h2 inside original h1? +1 for .tpl.php but please check that first part, OK?
    – Mołot
    Commented 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?,
    – madhurjya
    Commented Nov 28, 2013 at 12:06
  • If you confirm it's invalid then by al means you should.
    – Mołot
    Commented Nov 28, 2013 at 12:08
2

You can change the title, as well as h1 to h2, using view title like in the below screenshot

1
  • not working on Drupal 8
    – Augusto
    Commented Feb 8, 2019 at 10:07
2

You can trick this leaving empty the title view field and adding the title as a text on the header view area.

1

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 )

Screen shot on configuring the fields Screen shot on the html mark-u

2
  • This changes format of a title field of listed content, not the title of a view.
    – Mołot
    Commented 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
1

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.

  1. Copy the page.tpl.php file to a folder
  2. Rename the file (page--bike.tpl.php)
  3. Edit the file with your new tag (or another thing)
  4. Save the file
  5. Put the file in the same place of your page.tpl.php file
  6. Clean the cache
  7. Enjoy

Reference:

How to override Views use of page.tpl.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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