Score:0

How can I change the title of the node/add page of a specific content type?

cn flag

I want to change the title of the node/add page of a specific content type. Twig debug only shows me file names that would also change the titles of other content types. There was a module for this in D7, but unfortunately it was not ported to D8.

4uk4 avatar
cn flag
You could [alter the route](https://www.drupal.org/docs/drupal-apis/routing-system/altering-existing-routes-and-adding-new-routes-based-on-dynamic-ones) and replace this title callback [NodeController::addPageTitle](https://api.drupal.org/api/drupal/core%21modules%21node%21src%21Controller%21NodeController.php/function/NodeController%3A%3AaddPageTitle).
Score:1
cn flag

If you can hide the default page title using CSS, then you could create a custom block for the title and specify to have it show only on the content you want.

In the block configure visibility settings, set the page visibility to be restricted to your content type.

-- But, hiding the default page title block that will only work for you if the admin theme is using the same theme as the front-end site.

I think the admin page title is still passing through that Page title block (the default).. so maybe you can configure that block's visibility to hide on the edit pages where you want your custom block to appear?

0711master avatar
cn flag
The admin page doesn't matter, only the front end appearance is important
Score:0
cn flag

Simply use Metatag module. This is the no-code solution.

Use the metatags configuration for the specific content type. And then modyfy the Title field. With the Token module you have more power to modify the title.

Here and here is some documentation about how to use metatgs.

0711master avatar
cn flag
Apparently this option only changes the text within the title tags?
cn flag
@0711master yes. Otherwise - the question doesn't make sense, since you can edit the node title from the node edit form. If need automatically set the node title per content type - then use the module `autotitle`
0711master avatar
cn flag
Ah ok, I need to clarify: if you open any node/add page then the title you see directly above the node form is like "Add @type" with type being the name of the content type. This is the title I'm talking about.
cn flag
Then - see the answer at the bottom of your question: You could alter the route and replace this title callback NodeController::addPageTitle.
0711master avatar
cn flag
Thank you and I hope you are safe!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.