We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 48872
    • 14 Posts
    Ciao a tutti,
    ho realizzato un semplice snippet che inserisce il tag canonical in una pagina.
    Il comportamento di default è definire il canonical sulla pagina stessa.
    Se si è invece definito un symlink viene imposto come canonical il percorso
    puntato dal symlink. Spero possa essere utile.

    <?php
    $resource = $modx->getObject('modResource', array('id' => $modx->resource->get('id')));
    $class_key = $resource->get('class_key');
    $content = $resource->get('content');
    if ($class_key == 'modSymLink') {
    	if (is_numeric($resource->get('content'))) {
    		return "<link rel=\"canonical\" href=\"[[++site_url]][[~{$content}]]\">";
    	}	
    }
    return "<link rel=\"canonical\" href=\"[[~[[*id]]? &scheme=`full`]] \">";
    ?>
    
    [ed. note: simone.alati last edited this post 9 years, 7 months ago.]