Drupal - Add canonical tag in


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. }

URL: www.marlux.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.