Customization of “Submitted by” Node Field

When a user posts a new node content, by default there’s data below the title that provides info on the user who posted the content and the date on which it was posted. For example:

Submitted by Admin on Sat, 11/09/2013 – 21:05

Personally it took me a while to understand how this field could be customized for example to “Posted by Admin on 24 Mar 2014”. The customization involves:

  • template.php
  • a pre-processor function (which is placed in the template.php)
  • PHP date() function – it would be great if you had deeper understanding of this function. Just head over to PHP.NET for more info on this function.

In this case, I used Bartik as my template; the default template for any Drupal 7 installation. The pre-processor function used is the theme pre-processor for the node i.e.

function bartik_preprocess_node(&$variables) {


All pre-processor functions are housed either in the template.php file or in a module. Our customization process is quite small so there’s no need of creating a module (why create many files when we can write a few lines of code to accomplish our goal).

The following figure displays the default submitted info.


Customization of “Submitted by” was once accomplished through theme_node_submitted in Drupal 6 but in Drupal 7 you use the above pre-processor for the node. Our complete pre-preprocessor function will appear as follows:

function bartik_preprocess_node(&$vars) {
if (variable_get(‘node_submitted_’ . $vars[‘node’]->type, TRUE)) {
$date = format_date($vars[‘node’]->created, ‘custom’,’dS l, F Y’);
$vars[‘submitted’] = t(‘Posted on !datetime’, array(‘!datetime’ => $date));

$date variable stores the date format function i.e. format_date() which has three parameters:

  • The first parameter, $vars[‘node’]->created is a UNIX time stamp for the when the node was created. This needs to be formated
  • The second parameter is the format to use, in this case, custom. The format can otherwise be short, medium or long
  • The third parameter is the PHP date format derived from date() function. This parameter is optional but comes in use  only when the second parameter i.e. format is custom

!datetime is a placeholder for the array value of $date while the array member variable $vars[‘submitted’] stores the submitted info and is called by one of the .tpl.php template files as print $submitted e.g. node.tpl.php. For example:

<?php if ($display_submitted): ?>
<span class="submitted">
<?php print $user_picture; ?>
<?php print $submitted; ?>
<?php endif; ?>

Once the changes have been saved, the new submitted info should display as follows:


And that’s it. The power of Drupal’s flexibility.


Please follow and like us:

Leave a Reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see

June 19, 2014

Posted In: Information Technology

Tags: , ,

Leave a Comment