Drupal: Display Creation Date in Search Results

I've been pretty happy with this site since I migrated to Drupal a year ago.  Out of the box it's not as full-featured with respect to blogging as dedicated blogging tools like WordPress or MovableType, but that's not really an issue for me.  Plus, I've added bits and pieces to the site which have made it easier for me to use (post articles) and manage.

Still, there's been one issue that's been bothering me since the beginning and that has to do with how search results are displayed.

By default, search results are presented with each article's "last modified" date displayed.  Usually this is the proper behavior, but since I imported the site from WordPress last year all imported articles had a modified date of August 2009.  I did not like that, but my initial investigation in how to display the created date instead of the modified date yielded no results.

Fast forward to today when I decided to take another look.  Lo and behold, what did I find?  An excellent article that provided exactly the solution I needed, along with the instructions on how to implement it the right way, the Drupal way.  Thanks to Aaron over at the RoamingCoder for this wonderful fix!

Here's the link to Aaron's article on Displaying Creation Date in Drupal Search Results.

For my own reference, here are the details.  First, copy search-results.tpl.php and search-result.tpl.php from $drupalroot/modules/search to your theme's folder.  Then add the following code to search-result.tpl.php, right after the opening comments. If you don't see the created date in your search results, visit the theme admin page and resave your theme.

 if($type == "node"){
   $info_split[fusion_builder_container hundred_percent="yes" overflow="visible"][fusion_builder_row][fusion_builder_column type="1_1" background_position="left top" background_color="" border_size="" border_color="" border_style="solid" spacing="yes" background_image="" background_repeat="no-repeat" padding="" margin_top="0px" margin_bottom="0px" class="" id="" animation_type="" animation_speed="0.3" animation_direction="left" hide_on_mobile="no" center_content="no" min_height="none"]['date'] = format_date($result['node']->created, 'small');
   $info = implode(' - ', $info_split);



1 thought on “Drupal: Display Creation Date in Search Results”

  1. Thanks for this helpful information. In my case it only works after removing the surrounding

    if($type == “node”){ }

    I’m using Drupal 7.41.

Comments are closed.