Posted By

nicoknaepen on 02/17/12


Tagged

drupal canonical


Versions (?)

Drupal - Add canonical tag in


 / Published in: PHP
 

URL: www.marlux.com

For our project, this code had been implemented in the theme template.php

  1. function yourtemplate_preprocess_html(&$vars) {
  2. // get the request parameters
  3. $reqParams = explode('?', $_SERVER['REQUEST_URI']);
  4. $canon = 'http://www.marlux.com' . $reqParams[0];
  5. // create a canonical object
  6. $canonical = array(
  7. '#type' => 'html_tag',
  8. '#tag' => 'link',
  9. '#attributes' => array(
  10. 'name' => 'canonical',
  11. 'content' => $canon,
  12. ),
  13. );
  14. // add the canonical object to the html head
  15. drupal_add_html_head($canonical,'canonical');
  16. }

Report this snippet  

You need to login to post a comment.