How can I remove the links to old polls and results in Drupal 7? I unset view results for anonymous users, but they still can view results. I'd like to remove the link to old polls and poll results in template. Is it possible to do it? if the answer is yes, which code should I add to template.php to remove those links?

  • 1
    Rather than relying on the theme layer to accomplish this, you'd be far better off simply unpublishing the old polls.
    – jhedstrom
    Commented Apr 9, 2011 at 19:55

2 Answers 2


You can remove the links by either copying the poll-results--block-tpl.php template file to you theme and removing the line that prints $links or with template_preprocess_poll_results(&$vars) in your template.php file in your theme and removing the line that sets the links variable.


<div class="poll">
  <div class="title"><?php print $title ?></div>
  <?php print $results ?>
  <div class="total">
    <?php print t('Total votes: @votes', array('@votes' => $votes)); ?>


function template_preprocess_poll_results(&$variables) {
  if (isset($variables['vote']) && $variables['vote'] > -1 && user_access('cancel own vote')) {
    $elements = drupal_get_form('poll_cancel_form', $variables['nid']);
    $variables['cancel_form'] = drupal_render($elements);
  $variables['title'] = check_plain($variables['raw_title']);

  if ($variables['block']) {
    $variables['theme_hook_suggestions'][] = 'poll_results__block';
  • first method works but only when i remove it in poll module (not in template directory :( ). second method - i do not have such things in template.php
    – Alonso
    Commented Apr 9, 2011 at 14:18
  • the second method is a template override. you need to add that function to your template.php file and rename template_preprocess_poll_results to yourtheme_preprocess_poll_results. for the first method you need to clear cache when overriding template files.
    – Jepedo
    Commented Apr 9, 2011 at 14:32
  • @Alonso You have to add that function in template.php; if that file doesn't exist, then you need to create it. In the first case, it doesn't work because Drupal didn't recognize the theme has a new template file; if you just copied the file in the theme directory, that doesn't work. You need to make Drupal know the theme is changed, which can be done by disabling and re-enabling the theme, or cleaning the cache used by Drupal.
    – apaderno
    Commented Apr 9, 2011 at 14:34

Other way to do it will be using hook_block_view_MODULE_DELTA_alter()

function THEME_block_view_poll_recent_alter(&$data, $block) {

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.