Hello all,

In Drupal 7, I have disabled/hidden author info in my theme and content type, but the author still shows in search results and the "latest content" block.

I want to get rid of it, of course I could do it in CSS but that would only be front-end. I don't know how to solve it from the root of the problem.

Could anybody help me out with it?

Thanks a lot in advance :-)

Comments

dono1’s picture

chateau_dur,
     You obviously know in D7 you can now remove author/date info through the specific content types settings.

This also depends on if you are using a custom theme or using one of the default themes drupal 7 provides.

Things you can search through your "Themes" Code for are:

<?php print $submitted; ?>

/////OR

<?php print $source_date; ?>

/////OR

<?php if ($display_submitted): ?>

Search any of those or other relevant items and you'll find that solution somewhere.

In the Content Blocks, you may have to dig into the Modules code...

Then of course, you can delete that specific code and it will remove it. Always suggested not to mess with core elements, but the <?php print $submitted; ?> snippet shouldn't and won't do to much damage

dono1’s picture

You can go directly into the search module: modules/search

and locate search-result.tpl.php

and remove this:

<?php if ($info) : ?>
      <p class="search-info"><?php print $info; ?></p>
    <?php endif; ?>

$info is what provides the meta info in that module.

Make sure you make a copy of the search-result.tpl.php in case in the future it gets thrown off. There are other ways to do this.

Carolyn’s picture

It's a better practice to first copy the search-result.tpl.php file into your theme folder (in /sites/all/themes). Then you can remove that code in the copy and clear your theme registry, and it should work fine.

If you just edit that file directly, you will destroy your upgrade path. If you upgrade, those changes will be lost.

chateau_dur’s picture

Thank you everybody, you've been a great help.

I hope this thread will help others!

Cheers

Schmidt Attila’s picture

If you want to hide any content wich is generated by any php code add these lines to end of your style.css file:

.search-info {
	display: none;
}
sheila8stamp’s picture

Thanks Schmidt - that worked a treat!

mesr01’s picture

A clean, simple and official way of doing it is to copy the original template file (in this case d7root/modules/search/search-result.tpl.php) into your theme and remove from that file what you don't want (in this case, the last "if" statement). Do not modify contrib themes, instead create sub-themes. Template files in the active theme have precedence over default ones.

pjaxon’s picture

Super simple... thanks, much.

alboyd’s picture

Best, easiest result Thanks!

Beast.Matt’s picture

Shouldn't there be a way to do this with template.php or with a pre/postprocess? TPL edits should be a last resort and a display: none does not hide the text from search engines that read the generated html.

prossel’s picture

Yes there is a better way using template.php if you are using your own theme. If not, you can create a sub theme.

Add this function to template.php and don't forget to change YOUR_THEME_NAME:

/**
* Process variables for search-result.tpl.php.
*
* @see search-result.tpl.php
*/
function YOUR_THEME_NAME_preprocess_search_result(&$variables) {
  // Remove user name and modification date from search results
  $variables['info'] = '';
}
userofdrupal’s picture

Thanks prossel, exactly what I was looking for.

Anybody’s picture

In AdaptiveTheme there are several settings for this purpose!

http://www.DROWL.de || Professionelle Drupal Lösungen aus Ostwestfalen-Lippe (OWL)
http://www.webks.de || webks: websolutions kept simple - Webbasierte Lösungen die einfach überzeugen!
http://www.drupal-theming.com || Individuelle Responsive Themes

selva8187’s picture

Thanks Prossel. Its working well great solution

jkirkby’s picture

All this did for me was make the author name into a link

SandPond’s picture

As suggested, you should be able to turn this off under "Display Settings / Display author and date information" for content type. However, this has no effect on whether these attributes are displayed in search results.

It is not always desirable to show user info on public websites because this info is also the login name.

As mentioned, there are several ways to hack this issue, but none of them work cleanly. Each method still leaves an unwanted horizontal line after each search result. If revision history is being used, a horizontal line for each revision will also be rendered... even if all revisions have been deleted! Some of my search results show 8 or more horizontal lines after the search result. Possibly other problems are involved?

Because this issie originates in a root module, it seems that D7 core needs repair.

hvasconcelos’s picture

prossel's solution was pretty simply and it worked for me!

kerrycurtain’s picture

Prossel's solution worked perfectly in my subtheme. Thank you.

joshmbuck’s picture

prossel's solution worked for me too, but now I was wondering if there's a way to separate out the author and the date. That is, how would I amend prossel's code so that instead of it saying author and date posted it could say something like "This entry was posted on ."?

Is that possible? I'm assuming that it is, just not sure how to do that.

Thanks.

Josh

Anonymous’s picture

You can do that by overriding the template_preprocess_search_result function in your theme's template.php file.

If you look at the code example you'll see that the function sets an array named $info. The array contains four key / value pairs: 'module', 'user', 'date' and 'extra'. I'm not quite sure what's stored in 'module' but the others contain the user name, date published and other info, such as the number of comments.

To get the function to only show "This entry was posted on ..." you could copy the function to your theme's template.php file. Rename the function so that the first word is the name of your theme instead of 'template'. Then remove the values you don't want to use in search results and add "This entry was posted on " to $info['date'].

Here's an example. The theme I'm using is Boron; you'll need to change 'boron' to the name of your theme. Otherwise you should be able to just copy & paste...

function boron_preprocess_search_result(&$variables) {
  global $language;

  $result = $variables['result'];
  $variables['url'] = check_url($result['link']);
  $variables['title'] = check_plain($result['title']);
  if (isset($result['language']) && $result['language'] != $language->language && $result['language'] != LANGUAGE_NONE) {
    $variables['title_attributes_array']['xml:lang'] = $result['language'];
    $variables['content_attributes_array']['xml:lang'] = $result['language'];
  }

  $info = array();
  if (!empty($result['module'])) {
    $info['module'] = check_plain($result['module']);
  }
  if (!empty($result['date'])) {
    $info['date'] = 'This entry was posted on ' . format_date($result['date'], 'short');
  }
  // Check for existence. User search does not include snippets.
  $variables['snippet'] = isset($result['snippet']) ? $result['snippet'] : '';
  // Provide separated and grouped meta information..
  $variables['info_split'] = $info;
  $variables['info'] = implode(' - ', $info);
  $variables['theme_hook_suggestions'][] = 'search_result__' . $variables['module'];
}
kingandy’s picture

Like all preprocess hooks, hook_preprocess_search_result happens as well as template_preprocess_search_result, not instead of - it's not a theme override, it's more of a hook_alter type of a thing. That means the $variables array already includes info_split with all the values calculated here. Rather than starting from first principles you can just do this:

/**
* Implements hook_preprocess_search_result().
*/
function example_preprocess_search_result(&$variables) {
  unset($variables['info_split']['user']);
  $variables['info'] = implode(' - ', $variables['info_split']);
}

Note that this can also go in a module instead of a theme. That way you don't have to keep rewriting this every time you change your theme.

++Andy
Developing Drupal websites for Livelink New Media since 2008

kingandy’s picture

Oh, and to prefix the date like that, something like this:

function example_preprocess_search_result(&$variables) {
  if (!empty($variables['info_split']['date'])) {
    $variables['info_split']['date'] = t('This entry was posted on !date', array('!date' => format_date($variables['info_split']['date'], 'short')));
    $variables['info'] = implode(' - ', $variables['info_split']);
  }
}

++Andy
Developing Drupal websites for Livelink New Media since 2008

GiorgosK’s picture

similar to some of the solutions above but less cluttered (I think)

put in your theme's template.php and change THEMENAME to your theme's name

use only one of the below

function THEMENAME_preprocess_search_result(&$vars) {
  //delete user + date
  $vars['info'] = "";

  //delete user
  $vars['info'] = $vars['info_split']['date'];

  //delete date
  $vars['info'] = $vars['info_split']['user'];
}

------
GiorgosK
Web Development

hansnavas’s picture

Tried the code sample you have and it partially worked. The username is still showing up on my results.