Discussions

How to hide the label "Title" for products?

Is there a way to hide the label "Title" when displaying products? It seems to be impossible to hide the label of a title field.
Sure it's possible to hide the title field entirely and create another textfield where I can hide the label and use this field to display the title of my products. But that's an ugly solution. Is there a better way?

Thanks

Thomas

Posted: Mar 23, 2012

Comments

wickwood on February 5, 2013

I installed this module, but I could not find where I could remove the Title Label for a Product in a Product Display node. In fact, Commerce Product Types don't show up in the configuration for this module at all, only Content Type Nodes.

Maybe I'm missing something, it wouldn't be the first time!

Thanks for any additional help in advance!
Steve

quercus020 on December 18, 2012

I encountered this problem too. I found that if I installed the Display Suite module and changed the layout of the Product Display Node it actually gives you another title (Disabled) which is just called Title. If you then disable the normal Product:Title and replace it with the Title then you get a nice title without the label.
This is one of those stupid little things that I hate about Drupal Commerce.

wickwood on February 5, 2013

I already had Display Suite installed and this was what I tried first. But even with this I don't see any option to hide the Title Label for a Product in a Product Display node or in the Product Type Manage Display.

As I said above, maybe I'm missing something here too!

Thanks for any additional help in advance!
Steve

wickwood on February 5, 2013

Of course hiding the rendered code with CSS is always an option, but there should be a better way to do this. Are all the examples on KickStarter using CSS to hide the Title Label for the each Product Title?

Things like this drive me crazy!

Steve

valderama on May 8, 2013

You can use this snippet in a custom module to overwrite the output of the title.

function {my-module-name}_entity_view_alter(&$build, $type) {
  if ($type == 'commerce_product') {
    $build['title']['#markup'] = '<div class="commerce-product-title">' . $build['#entity']->title . '</div>';
  }
}

heddn on August 8, 2013

function hook_entity_view_alter(&$build, $type) {
if ($type == 'node') {
if (isset($build['product:title'])) {
$search = array('', 'Title: ');
$build['product:title']['#markup'] = str_replace($search, '', $build['product:title']['#markup']);
}
}
}

heddn on August 8, 2013

If you view the node, try this alternative.

function hook_entity_view_alter(&$build, $type) {
  if ($type == 'node') {
    if (isset($build['product:title'])) {
      $search = array('<div class="commerce-product-title-label">', 'Title:      </div>');
      $build['product:title']['#markup'] = str_replace($search, '', $build['product:title']['#markup']);
    }
  }
}

elpino on January 24, 2014

Add a template file called commerce-product-title.tpl.php in your theme.

In this example I have commented out the code that prints the label.

<?php

/**
 * @file
 * Default theme implementation to present the title on a product page.
 *
 * Available variables:
 * - $title: The title to render.
 * - $label: If present, the string to use as the title label.
 *
 * Helper variables:
 * - $product: The fully loaded product object the title belongs to.
 */
?>

<?php if ($title): ?>
  <div class="commerce-product-title">
    <?php /* if ($label): ?>
      <div class="commerce-product-title-label">
        <?php print $label; ?>
      </div>
    <?php endif;*/ ?>
    <?php print $title; ?>
  </div>
<?php endif; ?>