Kevin Shoesmith

Skip the windy preamble and go straight to the solution

The Problem

Sometimes it's troublesome to hide or remove page node titles in your Drupal theme. Too often the proposed way to hide page titles is clumsy and inflexible, effecting every content type on the site. 

One of the things that's always been a bit finicky about using Drupal for us has been how to control page node titles at the content type level. 

Until recently, we were aware of only a handful of ways to hide the default titles that most Drupal themes display for nodes automatically. Sometimes, if not most of the time, we didn't want those titles to appear because they either conflict with the proposed site architecture or we have some other reason for wanting to supress them. As easy as it is to rip out the code that displays titles from the page.tpl.php template, that approach prevents the title from appearing on any page of the site. The same goes for CSS related solutions like the display:none; option.

And there are other arduous., clumsy ways to achieve the effect too:

You could even get into your template and add a little conditional code or some form or another, to display titles only for certain pages, but you'd better know a little php; not the solution for everyone.

But what about cases where you don't want the titles to appear for say, a Basic Page content type or whatever, but you do want titles for your Article content types like blog posts and news items? Then you need something a little more elegant, a little more flexible and controlled.

The Solution

The Omega theme allows site admins to toggle page titles for display on their sites, as other themes likely do. And if you design your content layouts using Display Suite, then you have the perfect combination for controlling page titles with flexibility and ease.

The winning combination for hiding page titles in Drupal is the Omega Theme and Display Suite. Display Suite is an indispensible module for controlling how your content is rendered on your site for different layouts. While we've been using the Omega Theme for most projects  recently and know it best, this solution will likely work with any theme that allows admins to toggle page titles on and off.

Here's how we've been gaining control over our page titles in recent:

  1. Download and install Display Suite for Drupal and enable it. Do this using Drush. If you don't use Drush already, there are few things I'd recommend more to a new (or veteran) Drupal developer than to learn to use this tool.
  2. Turn off the Page Title display in your theme's settings. If you're using the Omega Theme, go to Appearance > "Your site sub-theme" Settings > Toggle advanced elements and deselect Page Titles if selected. This will turn off the Page Title display for all content type nodes on the site by default.


     

  3. Go to the Manage Fields area for the Content Type for which you wish to show page titles.

    Content types screenshot

    If you want to set different displays for different view modes, like Full Content, RSS, or Teasers, select those under the "Custom display settings" tab and click Save. Then select "Layout for content type in default" where content type is the type you're modifying and default is the view type. For example, if you're modifying the display for Articles in Full Content, the tab title will read "Layout for Article in Full". Select a layout from the dropdown menu, then click Save again.


     

  4. After saving, the Manage Display page should allow you to drag and drop fields to be displayed for that content type and display. You'll be able to modify settings in much the same way you can when creating views in the Views UI module. Make sure that Title is one of the enabled fields, then click Save.

    Screeshot
     

  5. Have a look at a node for that content type on the front side of the site to see if the page title appears, and style to taste.

This is a much, much more civilized method of controlling page titles than performing template surgery to remove titles like some kind of unwanted appendage. What's more, you now have control over what kinds of content will display page titles, and you can even assign them custom CSS classes and turn them into links too, if they're part of a list view for example.

Happy Drupaling! 

Factory Interactive is a Drupal development company based in Vancouver, BC, Canada.

 

Add new comment