When it comes to laying out the fields in a content type, the title field can be particularly annoying. Whether you are using Display suite, or you chose to build your own title field module (the option we prefer), you may have run into the issue of duplicate titles on a Full Content (or Default) display mode.
In most cases, you would not need to use a title field on the Default or Full Content display mode. By default, Drupal places it’s title block field above the content, and most designers want page titles at the top of the page. However, in the case of something like a Hero banner containing the title, or fields that render above the title, configuring the title placement becomes necessary.
Now, for my devs who want to just skip to the code (yes, we all do it), scroll to the bottom for the complete preprocess you need to remove the default Drupal page title. For all my curious minds, I’ll explain the preprocess and why this is the most foolproof option.
You may be asking "wait, why can’t I use the Drupal `Page Title` block visibility settings?"
Set up Preprocess
Let's break this down:
First, we check if we are on a node. It's important to have this check, or else your site will break when you are on other entity types (like a view).
Thanks to the Node function, we can simply use the getType() to check what kind of node we are on (Example: Article, Page, News). Then we make that information into a variable
Finally, we unset the default Page Title block on our desired content types. You can do this by finding the machine name of your page title block and inserting it in `YOURTHEME_page_title`. Often, the name matches whatever name you used for YOURTHEME in the beginning of your preprocess.
Putting it all together, your .theme file should look like: