We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3186 ☆ A M B ☆
    • 279 Posts
    Hi all,

    I want to create a google canonical tag on symlink pages to the original page. I have made a tv for this value (named: seoCanonical) and now I want to create the value when the page is loading. So I have made a plugin and linked it to the OnWegPagePrerender event. The plugin is working correctly but the value isn’t avalable on the first time viewing the page. Could anyone help me out?

    This is my ’AutoCanonical’ plugin

    $c = $modx->newQuery('modResource');
    $c->where(array(
    	'id' => $modx->resource->get('id'),
    	'class_key' => 'modSymLink'
    ));
    $orgResource = $modx->getObject('modResource', $c);
    
    if(!empty($orgResource) && is_object($orgResource)) {
    
    	$symlinkID = $orgResource->get('content');
    	$symlinkURL = $modx->makeUrl($symlinkID, '', '', 'full');
    
    	$tv = $modx->getObject('modTemplateVar', 4); // canonical tv
    	$tv->setValue($modx->resource->get('id'), $symlinkURL);
    	$tv->save();
    }


    Thanks in advance

    Regards, Bert
      MODX Ambassador (NL) & Professional MODX developer
      Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
      MODX e-commerce solution SimpleCart