1

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?

5
  • I assume editing it in the admin is not sufficient (perhaps for deployment purposes?)
    – Kevin
    Commented May 6, 2019 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
    Commented May 6, 2019 at 18:43
  • Based on @Clive's comment, looks like your code is not running.
    – No Sssweat
    Commented May 7, 2019 at 11:06
  • @Kevin Yes, it's for deployment. Commented May 7, 2019 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? Commented May 7, 2019 at 11:53

1 Answer 1

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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