$docId = $modx->resource->get('id');
$query = $modx->newQuery("modSymLink");
$query->select(array(
'id',
'class_key',
'content',
));
$query->where(array(
'id' => $docId,
'class_key' => 'modSymLink'
));
if ($query->prepare() && $query->stmt->execute()) {
$results = $query->stmt->fetchAll(PDO::FETCH_ASSOC);
}
if (!empty($results)) {
$id = (integer) $results[0]['content'];
$url = $modx->makeUrl($id, '', '', 'full');
return '<link rel="canonical" href="' . $url . '" />';
}
return '';