CMS Made Simple Forums

Add canonical links to your site [SEO]
Page 1 of 1

Author:  Peciura [ Wed Oct 06, 2010 3:09 pm ]
Post subject:  Add canonical links to your site [SEO]

Idea is to tell googol link to a page with only required url params. More info http://googlewebmastercentral.blogspot. ... nical.html

I created UDT that strips off extra params in url. Than it can be used as canonical url. This UDT is created for Products detail view but can easily be adopted to any other module. It uses "ugly" url and $config['process_whole_template'] = false;.
* Get product details canonical url
* @params string $params['url_param_list'] Comma separated list of parameters to be kept in new url. Default  'mact,cntnt01productid,hl'
* @params string $params['url'] URL to be modified. Default $config['root_url'].$_SERVER['REQUEST_URI'];
* @params string $params['assign'] Assign value to.

//prepare parameter
$url_param_list = 'mact,cntnt01productid,hl';
$url_param_list = trim($params['url_param_list']);
$config = cmsms()->GetConfig(); // cms_utils :: get_config();
$url = $config['root_url'].$_SERVER['REQUEST_URI'];
$url_param_list = trim($params['url']);
$return = array();

//modify url query
$query_string = parse_url($url, PHP_URL_QUERY);
$url_params_to_save = explode(',', $url_param_list);
parse_str($query_string, $data);
foreach($data as $key => $url_param){
if(!in_array($key, $url_params_to_save)){
$url_query = http_build_query($data, '', '&');

//recreate url
$return = str_replace($query_string, $url_query, $url);

//assign to smarty if needed
$smarty = cmsms()->GetSmarty(); // cms_utils :: get_smarty();
$assign = trim($params['assign']);
$smarty->assign($assign, $return);

Call it in Products detail template
{get_canonical_url assign='canonical_url' url_param_list='mact,cntnt01productid,hl'}

Add canonical link to meta data ("Site Admin ยป Global Settings > Global Settings > Global Metadata:")
{if !empty($canonical_url)}


Author:  dmaireroa [ Wed Dec 15, 2010 2:47 pm ]
Post subject:  Re: Add canonical links to your site [SEO]

I noticed no one hasn't replied yet. I was reading the link you sent earlier, and didn't know my site was using a 'www' and 'http://'.

Thanks, will look deeper into it.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group