There are many answers and tutorials addressing the problem of changing the machine name of a content type, or migrating content types. However, I would like to rename a content type, without changing the machine name. This is what I tried:

$type = node_type_load('my_content_type');
$type->name = 'A new name';

But this has no effect. What is the proper way to do this?

  • I assume editing it in the admin is not sufficient (perhaps for deployment purposes?) – Kevin May 6 '19 at 13:35
  • 3
    I copy/pasted your code into a D7 site, replaced my_content_type with page, and executed it...the name of the page node type was renamed to A new name as expected. How are you checking to see if the changes took effect? – Clive May 6 '19 at 18:43
  • Based on @Clive's comment, looks like your code is not running. – No Sssweat May 7 '19 at 11:06
  • @Kevin Yes, it's for deployment. – rudolfbyker May 7 '19 at 11:52
  • @NoSssweat I'm quite sure it's running. Maybe I should add that this is a content type defined by a module, and not created through the UI. Would that make a difference? – rudolfbyker May 7 '19 at 11:53

Looking back on this after a year, I can't reproduce my own problem. This code works, even for content types defined by modules, not created through the UI:

$type = node_type_load('my_content_type');
$type->name = 'A new name';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.