Function to get the node type of a node

Public

Pass either the node id or the node object already loaded. The returned value will be the machine name of the node type.

Get raw version
php
  1. function get_node_type($node) {
  2. $type = 'Error: You must pass either the node object or the node id.';
  3. if(is_numeric($node)) {
  4. $node = node_load($node);
  5. if(!empty($node->type)) {
  6. $type = $node->type;
  7. }
  8. } elseif(is_object($node)) {
  9. if(!empty($node->type)) {
  10. $type = $node->type;
  11. }
  12. }
  13. return $type;
  14. }