4

By default, in Drupal 7, the "Submitted by" date type is set to Medium. I want the "Submitted by" date to be rendered using a different type. How do I do this?

4 Answers 4

7

It's hard-coded into template_preprocess_node() so to override it you'll need to implement your own preprocess function, either in a theme or custom module:

function MYTHEME_preprocess_node(&$vars) {
  if (variable_get('node_submitted_' . $vars['node']->type, TRUE)) {
    $date = format_date($vars['node']->created, 'date_type');
    $vars['submitted'] = t('Submitted by !username on !datetime', array('!username' => $vars['name'], '!datetime' => $date));
  }
}
1
  • I agree with you, really hard-coded :).
    – Yuseferi
    Commented Sep 8, 2012 at 15:09
2

also If you wont(or couldn't) do it in theme(for any reason) .You can do it in your custom module.

function yourmodule_preprocess_node(&$variables) {

   $variables['date']= format_date($variables['created'] ,'your date format');
   $variables['submitted'] = $variables['date'] . ' — ' . $variables['name'];
  }
0

you can go to admin/config/regional/date-time/formats and add a new format using PHP date formats http://php.net/manual/en/function.date.php

then go to admin/config/regional/date-time and change Medium to your new added format.

0

The glazed theme does it as such:

// BLOG NODES
  if ($vars['type'] == 'blog') {
    $_created_date = format_date($vars['node']->created, 'custom', 'M j, Y');
    $vars['submitted'] = '<em class="text-muted">' . $_created_date . ' ' . t('By') . ' </em> <span class="glazed-util-text-uppercase">' . $vars['node']->name . '</span>';
  }

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.