10

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?

26

Drupal 8 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

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.
  • 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 Aug 3 '16 at 22:53
1

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

  • 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 Aug 3 '16 at 23:07

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.