0

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';
node_type_save($type);

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 at 13:35
  • 2
    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 at 18:43
  • Based on @Clive's comment, looks like your code is not running. – No Sssweat May 7 at 11:06
  • @Kevin Yes, it's for deployment. – rudolfbyker May 7 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 at 11:53

Your Answer

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

Browse other questions tagged or ask your own question.