Is it possible to alter the behavior of the Ajax pager? I have a problem with the way the Drupal 7 Ajax pager works on my website: when looking into the code, it creates links, then when one clicks on one of these links, the ajax.js catches this event and replaces "going to another page" with "loading a block with Ajax-retrieved content".

This causes an SEO problem. In fact, as the links for the Pager are declared like following:

&lt;a href="current-page?page=1"&gt;1&lt;/a&gt;


... it is therefore understood by crawlers as links to another page, even though they're not; during SEO analysis of my website, I get a Duplicate content between page "A" and page "A?page=1" notice.

Is there is a way to alter this behavior?
For example, how could I replace these links with elements that would have a dedicated attribute? I thought of replacing "a href=" with "span data-target=", for example, but I have no clue how to do this and didn't find any easy solution yet.

Would the amount of work be worth the gain in SEO?

~Stéphane
The way I fixed this was to take advantage of the way the Drupal/jQuery script for the "Views PHP" module's Ajax loading is working:


It looks for elements in the DOM with such structure : ul.pager &gt; li &gt; a 
it listens to a click event and calculates the data to be retrieved based on the "href" tag.
It operates its magic on the DOM.


My tweak is to modify line 8 of the "ajax_view.js" file so it also looks for ul.pager &gt; li &gt; span elements. Then, I add a hook in my theme's "template.php" file with the following code:

function THEME_pager($variables) {
  $output = "";
  $items = array();
  $tags = $variables['tags'];
  $element = $variables['element'];
  $parameters = $variables['parameters'];
  $quantity = $variables['quantity'];

  global $pager_page_array, $pager_total;

  $pager_middle = ceil($quantity / 2);
  $pager_current = $pager_page_array[$element] + 1;
  $pager_first = $pager_current - $pager_middle + 1;
  $pager_last = $pager_current + $quantity - $pager_middle;
  $pager_max = $pager_total[$element];

  $i = $pager_first;
  if ($pager_last &gt; $pager_max) {
    $i = $i + ($pager_max - $pager_last);
    $pager_last = $pager_max;
  }
  if ($i &lt;= 0) {
    $pager_last = $pager_last + (1 - $i);
    $i = 1;
  }
  $li_previous = ($pager_current &gt; 1) ? '&lt;span class="progress-enabled" href="?page=' . ($pager_current - 2) . '%2C' . ($pager_current - 2) . '"&gt;' . (isset($tags[1]) ? $tags[1] : t('previous')) . '&lt;/span&gt;' : NULL;
  $li_next = ($pager_current &lt; $pager_max) ? '&lt;span class="progress-enabled" href="?page=' . ($pager_current) . '%2C' . ($pager_current) . '"&gt;' . (isset($tags[3]) ? $tags[3] : t('next')) . '&lt;/span&gt;' : NULL;
  if ($pager_total[$element] &gt; 1) {
    if ($li_previous) {
      $items[] = array(
        'class' =&gt; array('prev'),
        'data' =&gt; $li_previous,
      );
    }
    if ($i != $pager_max) {
      if ($i &gt; 1) {
        $items[] = array(
          'class' =&gt; array('pager-ellipsis', 'disabled'),
          'data' =&gt; '&lt;span&gt;…&lt;/span&gt;',
        );
      }
      for (; $i &lt;= $pager_last &amp;&amp; $i &lt;= $pager_max; $i++) {
        if ($i &lt; $pager_current) {
          $items[] = array(
            'data' =&gt; '&lt;span class="progress-enabled" href="?page=' . ($i - 1) . '%2C' . ($i - 1) . '"&gt;' . $i . '&lt;/span&gt;'
          );
        }
        if ($i == $pager_current) {
          $items[] = array(
            'class' =&gt; array('active'),
            'data' =&gt; l($i, '#', array('fragment' =&gt; '', 'external' =&gt; TRUE)),
          );
        }
        if ($i &gt; $pager_current) {
          $items[] = array(
            'data' =&gt; '&lt;span class="progress-enabled" href="?page=' . ($i - 1) . '%2C' . ($i - 1) . '"&gt;' . $i . '&lt;/span&gt;'
            );
        }
      }
      if ($i &lt; $pager_max) {
        $items[] = array(
          'class' =&gt; array('pager-ellipsis', 'disabled'),
          'data' =&gt; '&lt;span&gt;…&lt;/span&gt;',
        );
      }
    }
    if ($li_next) {
      $items[] = array(
        'class' =&gt; array('next'),
        'data' =&gt; $li_next,
      );
    }
    return '&lt;div class="text-center"&gt;' . theme('item_list', array(
      'items' =&gt; $items,
      'attributes' =&gt; array('class' =&gt; array('pagination')),
    )) . '&lt;/div&gt;';
  }
  return $output;
}


It works perfectly for my usage.

Note : I know a "href" tag is technically illegal in a "span" element, but I didn't want to dig too deep in Drupal's JS ;)

~Stéphane