4

It has been recommended by an SEO consultant that for paginated pages the page number is included in the page title to avoid duplicated content. How do I achieve this?

I did this:

    function hook_pager_link($variables){
  $text = $variables['text'];
  $page_new = $variables['page_new'];
  $element = $variables['element'];
  $parameters = $variables['parameters'];
  $attributes = $variables['attributes'];

  $page = isset($_GET['page']) ? $_GET['page'] : '';
  if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
    $parameters['page'] = $new_page;
  }

  $query = array();
  if (count($parameters)) {
    $query = drupal_get_query_parameters($parameters, array());
  }
  if ($query_pager = pager_get_query_parameters()) {
    $query = array_merge($query, $query_pager);
  }

  // Set each pager link title
  if (!isset($attributes['title'])) {
    static $titles = NULL;
    if (!isset($titles)) {
      $titles = array(
        t('« first') => t('Go to first page'),
        t('‹ previous') => t('Go to previous page'),
        t('next ›') => t('Go to next page'),
        t('last »') => t('Go to last page'),
      );
    }
    if (isset($titles[$text])) {
      $attributes['title'] = $titles[$text];
    }
    elseif (is_numeric($text)) {
      $attributes['title'] = t('Go to page @number', array('@number' => $text));
    }
  }

  // @todo l() cannot be used here, since it adds an 'active' class based on the
  //   path only (which is always the current path for pager links). Apparently,
  //   none of the pager links is active at any time - but it should still be
  //   possible to use l() here.
  // @see http://drupal.org/node/1410574

  //put the pagination page number into the title tag
  $attributes['href'] = url($_GET['q'], array('query' => $query));
  //add page
  $page = t('page');
  $pattern = '/' . $page . ' \d/';
  $title = drupal_get_title();
  preg_match($pattern, $title, $matches);
  if(!$matches){
    $new_title = $title . ' - ' .  t('page') . ' ' . ($page + 1);
    drupal_set_title($new_title);
    }
  return '<a' . drupal_attributes($attributes) . '>' . check_plain($text) . '</a>';
}
4

Have you investigated the Page Title module? It, among other things, features

Pagination Suffix: One of the things you may noticed about Drupal in terms of SEO is that whenever you go through a paged list of content, the page title never changes. Google Webmaster Tools will flag this up as a problem as you essentially have several different pages all being identified with the same page title. A new feature, introduced in Page Title 2.1, is the ability to append the page number as a suffix pattern. This means any URL which contains something like page=2 in the query string will also have an optional token pattern suffixed onto the end of it. Important: for this feature to work properly, you need to be running Token 1.12 or later.

  • This would be very useful I would imagine. – Andrew Welch Feb 6 '14 at 11:42
  • The mentioned module is not used anymore... Use drupal.org/project/metatag – Benedikt Feb 8 '19 at 8:11
  • Just use something like [current-page:title] [current-page:page-number] | [site:name] – Benedikt Feb 8 '19 at 8:20
1

If you have to set other tags or configration related to SEO I suggest you Metatag module, that helps also with page title.

  • Curious to know how I would avoid the number to show up on the first page. – Benedikt Feb 8 '19 at 8:27
  • In this case you could alter the metatag using hooks in a module or in your theme – arrubiu Feb 9 '19 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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