11

In Drupal 8, is there an easy way to configure a page so that its page header/title is not displayed on the page?

I have created a Basic Page, with /home as path alias, and Home as title. I set it as front page. However, it displays 'Home' at the top of the page, just below the navbar and breadcrumbs.

Is it necessary to create a subtheme of the 'Bootstrap' theme, and somehow add custom CSS?

3 Answers 3

33

Drupal 8/9 places the page title in its own block (called Page title). You can control when and where that block displays on the block layout page: /admin/structure/block

0
2

you can also use this module for drupal 8 https://www.drupal.org/project/exclude_node_title

  • This module handles a very simple functionality, decide whatever to exclude a node title from full node page or node teasers. It provides a checkbox on node-edit pages for easier exclusion. Also provides the option to hide all titles of a certain Content type. From the administrative interface you can select a content type to hide title for.
2
  • 1
    Thank you very much for recommending this module, naveen. I was looking for something simple, out-of-the-box, which is why I selected acrosman's answer. However, your suggestion would seem to work equally well, and is actually preferred if wanting to hide the title based on the content type. I have made a bookmark to that module in case that need arise for me. Thank you very much again for your help!
    – kvjava1
    Commented Aug 3, 2016 at 22:53
  • I would caution users about this module; we've installed it an have used it for a while, but have run into a couple surprise gotchas: 1. It is not integrated with views, so you cannot create a view that indicates which nodes have their titles excludeded (drupal.org/project/exclude_node_title/issues/3065469), and 2. it is not stored in revisions, so if you are looking at the revision history of a node, it will be displayed with its title no matter what, even if that revision was set to exclude node title (drupal.org/project/exclude_node_title/issues/3077257).
    – user1359
    Commented Aug 26, 2019 at 20:57
2

You can do this entirely with CSS. You need to target that node which you are using as HOME page.

Now, Drupal-7 was generating specific class for each node. And this way it was easy to target each individual node and we were able to apply the specific CSS to that particular node.

But, in Drupal 8 this property is not available, hence we need to add this. follow following steps. I am showing this using Bartik theme as I do not have familiarity with Bootstrap theme. You can do with bootstrap theme also. It is pure CSS, so no sub-theming necessary.

1. Add the function to bartik.theme file.

if ($node = \Drupal::request()->attributes->get('node')) {
    $variables['attributes']['class'][] = 'page-node-' . $node->id();
  }

in the section of,

function bartik_preprocess_html(&$variables) {   

}

Why I am showing this way, because there is already other codes in function bartik_preprocess_html(&$variables), so add this function as last line.

Clear cache,

2. Get the CSS for that node

Now, if you do Inspect element on that particular node. You can find the class in <body></body> section as page-node-XX.

3. Go to core/themes/bartik/css/components/page-title.css, and add following code in that,

.page-node-XX .page-title {
 display: none;
}

Clear cache,

Now, this way you can target that particular node and you can do whatever CSS you want to apply.

Credit for function code: Link

1
  • CodeNext, thank you very much for your detailed answer. I actually was able to accomplish what I needed to do before, as a quick hack, by adding the following CSS to my subtheme's styles.css file: .page-header { display: none; } However, acrosman's answer seemed to offer the simplest approach. I did like your answer as well because it helps to understand the internals of how theming is working in Drupal8. Thanks again! I really appreciate it.
    – kvjava1
    Commented Aug 3, 2016 at 23:07

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.