Hi everyone,

I created a new content type where I'd like to put in some quotes. The text itself is in the description-field - so there is no need for a title. Is there a possibility how I can hide the title on the site or leave the title blank?
This should only be for this single content type, not for the whole site!

Thanks for your help :-)

--stonie10

Comments

vm’s picture

you can:

A) use a space for the title

B) investigate the autonodetitle.module

C) leave the title field and use a custom.tpl.php file in the form of node-CONTENTTYPE.tpl.php and leave the title out.

ronan’s picture

One of the quickest ways to do this is to add

if( $page ) {
$GLOBALS['supress_title'] = true;
}

to your node-xxx.tpl.php file and

<?php if ($title != "" && !$GLOBALS['supress_title']  ): ?>
      <h2 class="content-title"><?php print $title ?></h2>
<?php endif; ?>

or similar to your page.tpl.php.

It's not the cleanest way to do it but it works and it's easy.
------------------------------------
Ronan - Gorton Studios - http://www.gortonstudios.com/

------------------------------------
Ronan
Founder - NodeSquirrel - https://www.nodesquirrel.com/
Agency Tools Lead - Pantheon - https://www.pantheon.io/

stonie10’s picture

Wow, thanks for the fast help! :-)

I will try these two methods and see if it works for me.

--stonie10

mr_dimsum’s picture

Isn't there a way to completely modify the Create Content Type pages so fields are completely withheld from the user? Would this be the approach to do it.. Or is there not an existing module that can apply this rather than making overriding thematic pages?

ronan’s picture

You may be talking about the contemplate.module which allows for altering the display of fields without editing templates. Unfortunately the title field is not handled at the content type level, but is displayed by page.tpl.php, so there's no good way to suppress the page title without touching that file. Somebody should correct me if they've found a better way to do this though.

------------------------------------
Ronan - Gorton Studios - http://www.gortonstudios.com/

------------------------------------
Ronan
Founder - NodeSquirrel - https://www.nodesquirrel.com/
Agency Tools Lead - Pantheon - https://www.pantheon.io/

mr_dimsum’s picture

Hello Ronan,

Thanks for the quick reply. I never knew the Contemplate module also handles the Content Type creation pages as well. I assumed it was only able to modify/manipulate how the content is displayed and omit/remove items from being seen. I haven't had any experience with the module first hand, so I may be wrong. You're basically saying it can do both?

vm’s picture

yes it can do both, if you don't want fields to be seen you just omit them (the variables) from the tpl.php file.

Ultimately you can add other variables as well, as contemplate will show you everything that is available to the tpl.php. What you use or don't use for that matter, is your choice.

summit’s picture

Hi,

Is it then possible then to hide a nodetype from the content create ("node/add") page, for instance a ""forumreply" nodetype, which you still want to show the users on other pages?
greetings,
Martijn

hardik jayeshbhai hihoriya’s picture

i have created code hide page title

if(isset($variables['node']) && $variables['node']->type == 'home_page')
{
$variables['title'] = FALSE;
Or it may be the following - I haven't checked
$variables['node']->title = FALSE;
}

Deepak Newase’s picture

1.Create custom module
2.Enable this custom module
3.Write below mentioned code in the .module file of the custom module : 
  This code used to hide the title field from the given formid (CUSTOM_MODULE_FORM_ID)

    function CUSTOM_MODULE_NAME_form_alter(&$form, $form_state, $form_id){
      if ($form_id == 'CUSTOM_MODULE_FORM_ID') { 
           $form['title']['#access'] = FALSE;   
      }  
    }

4.Write another code which is used to set "Default Title" to the title value and saved in DB

use Drupal\Core\Entity\EntityInterface;
function presave_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
  if ($entity->bundle() == 'CONTENT_TYPE_NAME') {
        $entity->setTitle('Default Title');
  }
}