How to Remove Joomla’s Canonical Tag Without Hacking the Core

remove joomla canonical urls

For reasons detailed in an earlier post about why Joomla canonical urls are not implemented correctly it may be that you want to remove them. That's pretty easy by hacking the core, but safer to unset the tag in your template so the changes don't get wiped out on an upgrade.

This is quite easy to do in your templates index.php file.

The first thing we need to do is get the head information by calling the document. Once we have that we can loop through the links and remove any which have a relationship value of canonical.

$doc = JFactory::getDocument();
 foreach ( $doc->_links as $k => $array ) {
 if ( $array['relation'] == 'canonical' ) {
 unset($doc->_links[$k]);
 }
 }

If you check your site again now the canonical url will have been removed.

If you want to add your own canonical links using Joomla's custom fields, then check out this post.