I have a content type called "Blog post" (machine name = blog_post).

I've set up a custom node template that works properly called "node--blog_post.tpl.php"

I'd like my $submitted output to be "by User Name | Month, Day of Month, Year" (example - "by John Smith | November 2, 2016"

I've been working on this for 2-3 hours without being able to have any effect on the output, and have gotten to the point in my searching where the only links I'm finding that seem relevant are things I've already clicked on. I'm stuck.

I know there are multiple ways to do this, but I'm looking for how to make this happen using a theme_preprocess_node function in the template.php file. Not only because I've seen multiple posts saying this is the "best practice", but also to gain more familiarity with the template.php file itself & how it is used.

Any thoughts?

1 Answer 1


You can do this.In your theme_preprocess_node function create a new variable which is used in your node--blog_post.tpl.php .

 function yourtheme_preprocess_node(&$variables) {
 $node = $variables['node'];
  if ($node->type == 'blog_post') {
    $created = $node->created;
    $date = date('F j,Y', $created);
    $name = $node->name;
    $variables['new_variable'] = "By ".$name." | ".$date;

then print this new_variable in your tpl like this.

  <div class="content clearfix"<?php print $content_attributes; ?>>
  // We hide the comments and links now so that we can render them later.
  print render($content);
  print $new_variable;

Output show like this enter image description here


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.