I have some nodes I update frequently, but in content pane I can see the posting date of node.

How can I make Drupal 7 show the date of the latest edit, instead of the posting date?

2 Answers 2


You can use hook_node_view to add the change date content like this:

* Implement hook_node_view()
function youmodule_node_view($node, $view_mode, $langcode) {

    $changde_date = date('l jS \of F Y h:i:s A', $node->changed);
    $node->content['body'][0]['#markup'] = "<div class='changed-date'>$changde_date</div>" . $node->content['body'][0]['#markup'];

enter image description here


I would tackle this in a template_preprocess_node, either in a module or in your theme.

function mytheme_preprocess_node (&$variables)
   $variables['date'] = format_date($variables['node']->changed);

Depending on your node template, you may also want to do something like

function mytheme_preprocess_node (&$variables)
   $variables['date'] = format_date($variables['node']->changed);

   if (variable_get('node_submitted_' . $variables['node']->type, TRUE)) {
     $variables['display_submitted'] = TRUE;
     $variables['submitted'] = t('Edited by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['date']));
     $variables['user_picture'] = theme_get_setting('toggle_node_user_picture') ? theme('user_picture', array('account' => $node)) : '';
   } else {
     $variables['display_submitted'] = FALSE;
     $variables['submitted'] = '';
     $variables['user_picture'] = '';

so that your new $date gets used in $submitted, due to the preproccess/process order.

You can also play around with variants. For example, you could have both created and last edited dates; you would juust need to set up the variables in the preprocess function, and then use them in your node.tpl.php.

  • What file in my themes folder would I be looking for to place the code into? Also, when updating node.tpl.php, all that you would have to do is call print $var; where you want it placed correct? Jan 12, 2012 at 21:01
  • You would do this in template.php. Change mytheme to the name of your theme, and clear all caches. And yes, you would use print to output the variable. The template file will have lots of examples.
    – mpdonadio
    Jan 12, 2012 at 21:28

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.