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>.

3

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

  • 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 May 29 '17 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? – YellowWebMonkey May 29 '17 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 May 29 '17 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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