K
K
Ken Jee2018-10-16 14:32:28
MODX
Ken Jee, 2018-10-16 14:32:28

Why might the Canonical plugin not work?

Installed the Canonical add-on on ModX Revo ( https://docs.modx.com/extras/revo/canonical), inside the ... section added a call to the snippet. The result of the work is an empty line in the html code. What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
display: block, 2018-10-16
@Machez

The condition in the snippet fails - this page doesn't need link=canonical.

The code
$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 '';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question