I read on How do I remove the "submitted by" text on node display? where you can remove this in the content type settings for the node itself, but is there a way to only change the teaser so it does not display "submitted by" text?

I'm looking for a non-preprocess function or module way to do this; I can't use my theme to deal with it.

I was hoping to avoid using Computed Field module for something so trivial.

  • Display Suite will do the trick. – ril44 Apr 18 '12 at 0:45

That setting is checked and the information added in template_preprocess_node().

Which means that there is no other way than a preprocess function to change this. However, there is nothing stopping you from adding a preprocess function to a module, that works perfectly fine. You just need to make sure that your module runs after node.module by setting the weight in the system table to something higher than node (probably 0).

Code example by will:

In your .install file:

  ->fields(array('weight' => 1))
  ->condition('type' => 'module')
  ->condition('name' => 'moduleName')

And then in the .module file:

function moduleName_preprocess_node(&$variables) { 
  // Do not display post information on teasers
  if ($variables['teaser']) {
    $variables['display_submitted'] = FALSE;
| improve this answer | |
  • thanks so much! i didn't realize it was so easy to set the weight in the system table. great stuff. the regex solution is nice as well but i usually save that type of thing until the last resort. much appreciated. i'll post some code to make this more clear – will May 26 '11 at 0:05
  • posting code sounds great, feel free to simply edit my answer and put it in there. – Berdir May 26 '11 at 0:08
  • so to follow up, just put this in your moduleName_install function in your moduleName.install file: db_query("UPDATE {system} SET weight = [1] WHERE type = 'module' AND name = 'moduleName'"); and this in your moduleName.module: function moduleName_preprocess_node(&$variables) { // Do not display post information only on teasers $node = $variables['node']; if ($variables['teaser']) { $variables['display_submitted'] = FALSE; } } – will May 27 '11 at 23:34

If you're comfortable with regex you could use hook_node_view to add a '#post_render' variable to the $node->content:

function myModule_node_view($node,$view_mode){
function myModule_post_render_teaser($rendered){
  $regex='';//This selector would have to grab the rendered "meta submitted" div
  return preg_replace(etc. etc.);
| improve this answer | |
  • $regex = '/<div .*(?:class)\s*=([\'"]).*(?:submitted)[^>]*>[^<\/div>].*<\/div>/imsU'; – Trey May 25 '11 at 19:48
  • Why would you want to do that with a regex when it can be done easily with a preprocess function (which can be in a module too)? :) – Berdir May 25 '11 at 22:04
  • "I'm looking for a non-preprocess function" :) I agree preprocess is the best way to handle it, I was just catering to his request:) – Trey May 25 '11 at 22:13
  • On complex sites I frequently include two modules, one that has a high system weight and one with a low system weight, this would only be a viable solution if your module provides some function that needs to run before node.module... but to reiterate... Berdir has the right solution ;) – Trey May 25 '11 at 22:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.