Hi all,

In my D7 zen theme I want no title displayed for the content type 'page'.

So can anyone please tell me the correct way to do this?

I have tried adding a function to template.php which I have heard works in other themes but for me gives error messages =

http://tinyurl.com/5ww2a34

I have tried added the following to the bottom of template.php

function zen_process_page(&$variables) {
  if($variables['node']->type == 'page') {
    $variables['title'] = '';
  }
}

=

Notice: Undefined index: node in zen_process_page() (line 331 of .../sites/all/themes/zen/template.php).
Notice: Trying to get property of non-object in zen_process_page() (line 331 of .../sites/all/themes/zen/template.php).
line 331 being if($variables['node']->type == 'page') {

OR...

function zen_process_page(&$variables) {
$node = $variables['node'];
if ($node->type == 'page') {
$variables['title'] = '';
  }
}

=

Notice: Undefined variable: node in zen_process_page() (line 331 of /...sites/all/themes/zen/template.php).
Notice: Trying to get property of non-object in zen_process_page() (line 331 of...sites/all/themes/zen/template.php).

Any suggestions please?

Thank you

Comments

n8tron’s picture

This could also be accomplished with CSS:

.node-type-page #page-title  {
 /* accessible hiding */
  position: absolute !important;
  clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
  clip: rect(1px, 1px, 1px, 1px);
}
juc1’s picture

@ n8tron, thanks for your reply. I tried a variation of your suggestion which seems to work fine:

.node-type-page #page-title {
display:none;
}

Is there any problem with this?

Thanks

johnalbin’s picture

Status: Active » Fixed

It depends on if you want the page title to be accessible or not. The "display: none" method means that screen reader users will not be able to read that text.

Also, the problem with your PHP was that not all pages (like the default front page) have a $node variable set. You have to first check for the existence of the variable before you use it; that will prevent the PHP Notices you were getting.

if (isset($variables['node']) && $variables['node']->type == 'page') {
  $variables['title'] = '';
}
juc1’s picture

@ JohnAlbin, sorry for being thick but where does your code go? I have added it to the bottom of template.php just before my functioned mentioned above but I am still getting the same error message.

Thank you

PMorris’s picture

A non-code option I've been using is the Display Suite module. It has really nice customization for content types. You can just set node titles for a content type to be 'hidden'

I'm really liking it so far but I'm not sure if you get a performance hit or not. Haven't run too many tests.

http://drupal.org/project/ds

johnalbin’s picture

in your sub-theme's template.php file, you need this:

function STARTERKIT_preprocess_page(&$variables) {
  if (isset($variables['node']) && $variables['node']->type == 'page') {
    $variables['title'] = '';
  }
}

where STARTERKIT is replaced with the actual name of your theme.

johnalbin’s picture

Also, I too have heard good things about Display Suite. Though I haven't used it.

tom09’s picture

Component: PHP Code » layout.css

Hi,
Sorry I am quite new to Drupal and thus could not figure out how DS can help me to prevent the node title to be displayed. I checked all settings but there was nothing like a "content type to be 'hiddden'". Can you please elaborate a little bit more on the steps to get that working?

johnalbin’s picture

Component: layout.css » PHP code

@tom09 You'll have to ask over in Display Suite's issue queue or in IRC. I have no clue. :-)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

joostvdl’s picture

Status: Closed (fixed) » Active

$variables['title'] does not exist. So it can't be override like this.

neek’s picture

nice solution, but after this "home link (sites name)" thinks that this is a frontpage so here is no link to main page from node.

maurice13’s picture

Hi,
This is ok for me.
Now i want hide title for taxonomy content. How can i do?

johnalbin’s picture

Status: Active » Closed (fixed)

The original support request has been closed. Closing again.