1

I'm going to explain: I'm new to Joomla! and I have 3 modules in which I have to rewrite the URLs for SEO purposes.

In order to rewrite URLs has been provided this solution on SE WebMasters. It implies me to add a <link> tag in the <head> of the page so I would like to know if there is a Joomla-core method with which I can add such tag in the <head>.

1 Answer 1

2

In general, below is the code.
$doc = JFactory::getDocument();
$doc->addHeadLink(htmlspecialchars(JURI::current()), 'canonical');

I was looking for the Joomla documentation and only found one from Joomla 1.7. Not sure if the documentation just hasn't been updated or there have been some changes. https://docs.joomla.org/API17:Subpackage_Document

3
  • addHeadLink() isn't a core php function - so it can't be called like this - this should be JDocumentHTML::addHeadLink(); or $doc = JFactory::getDocument(); $doc->addHeadLink();
    – FFrewin
    Commented May 29, 2017 at 13:04
  • Thanks @FFrewin, I made the edit. I just did a sloppy copy/paste from file on my computer. Do you know if the documentation is just out of date or are they moving away from this? Commented May 29, 2017 at 13:22
  • haven't check the link you posted - although this is the J17 API - and currently I don't have the time to review and compare the old API with the new one for any differences.
    – FFrewin
    Commented May 29, 2017 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.