CMS Made Simple Forums
https://forum.cmsmadesimple.org/

Add canonical links to your site [SEO]
https://forum.cmsmadesimple.org/viewtopic.php?f=4&t=47938
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;.
\$1:
/**
* 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
if(empty($params['url_param_list'])){
$url_param_list = 'mact,cntnt01productid,hl';
}
else{
$url_param_list = trim($params['url_param_list']);
}
if(empty($params['url'])){
$config = cmsms()->GetConfig(); // cms_utils :: get_config();
$url = $config['root_url'].$_SERVER['REQUEST_URI'];
}
else{
$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)){
unset($data[$key]);
}
}
$url_query = http_build_query($data, '', '&');

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

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


Call it in Products detail template
\$1:
{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:")
\$1:
{if !empty($canonical_url)}

{/if}

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
http://www.phpbb.com/