Julio Franco
Member
We are working in integrating our site’s main backend and xenforo. One of the things we need is to customize the canonical url for threads (only threads in a specific forum) and some member pages (staff members), but we can’t figure out how to do this correctly:
The first thing we tried was writing an addon and extend the Thread Controller:
That code is trying to redirect to the new url, but we don't want to redirect just use that url as the canonical in meta for the thread.
Can you help us with some idea about what method we need to overwrite? or how is the best way to do this? Thank you!
The first thing we tried was writing an addon and extend the Thread Controller:
Code:
class Thread extends XFCP_Thread
{
protected $myCanonical = null;
public function actionIndex(\XF\Mvc\ParameterBag $params)
{
$res = parent::actionIndex($params);
if ($somecondition) {
$this->myCanonical = 'mycanonical.com';
}
return $res;
}
public function assertCanonicalUrl($linkUrl)
{
if(property_exists($this, 'myCanonical') && $this->myCanonical) {
$linkUrl = $this->myCanonical;
}
return parent::assertCanonicalUrl($linkUrl);
}
}
That code is trying to redirect to the new url, but we don't want to redirect just use that url as the canonical in meta for the thread.
Can you help us with some idea about what method we need to overwrite? or how is the best way to do this? Thank you!
Last edited: