0
Welcome Guest! Login
0 items Join Now

SOLVED Adding Canonical PHP Code Without Override

  • SOLVED Adding Canonical PHP Code Without Override

    Posted 9 months 1 week ago
    • Hello support,

      I am using these instructions here to add in canonical tags to each page of my website. Most of this is pretty simple and straighforward, however, there is one section asking to make a template override.

      I was wondering if there was a smarter way to do this inside of a Rocket Theme template (like in the head properties section or something) to avoid making an override? If this is the only way to achieve my goal, I understand, however, I was wondering if there was a smarter way that avoids overrides.

      Thank you,
      Geoffrey
    • Last Edit: 9 months 1 day ago by Geoffrey13.
    • Geoffresh SEO Web Design
    • Matt's Avatar
    • Matt
    • Preeminent Rocketeer
    • Posts: 22234
    • Thanks: 3219
    • messin' with stuff

    Re: Adding Canonical PHP Code Without Override

    Posted 9 months 1 day ago
    • Yeah, you can create a new Outline for any page you'd like and then you can use the Page Settings tab to add code the <head> including creating whatever meta tags you want

      docs.gantry.org/gantry5/configure/page-settings
    • SEARCH the forum first! These boards are rich in knowledge and vast in topics. This includes searching just the 'Solved' forums, using Google, and using ChatGPT :woohoo:
  • Re: Adding Canonical PHP Code Without Override

    Posted 9 months 1 day ago
    • Hi Matt,

      Thank you for your support on this. Would the head section allow for PHP code? Here is the snippet that the instructions are asking to make a template override for. If so, do I add this to the "custom content" section?


      //Check custom fields for canonical link
      foreach ($this->item->jcfields as $field) {
      	if ($field->title === 'Canonical URL') {
      		//Make sure the field isn't empty
      		if ($field->rawvalue !== '') {
      			$canonicalLink = '<link rel="canonical" href="' . $field->rawvalue . '" />';
      			$document = JFactory::getDocument();
      			$document->addCustomTag($canonicalLink);
      		}
      		continue;
      	}
      };
    • Geoffresh SEO Web Design
    • Matt's Avatar
    • Matt
    • Preeminent Rocketeer
    • Posts: 22234
    • Thanks: 3219
    • messin' with stuff

    Re: Adding Canonical PHP Code Without Override

    Posted 9 months 1 day ago
    • No, the page settings area is for frontend page content only... JS scripts, CSS, HTML, etc... php all has to be processed on the server first and here, using a Joomla template override would be the easiest option... Gantry can parse and load PHP via Twig but it's a more complicated process than just using a J! page template override.

      If you're curious: docs.gantry.org/gantry5/advanced/php-functions
    • The following users have thanked you: Joe Halleck

    • SEARCH the forum first! These boards are rich in knowledge and vast in topics. This includes searching just the 'Solved' forums, using Google, and using ChatGPT :woohoo:
  • Re: SOLVED Adding Canonical PHP Code Without Override

    Posted 9 months 1 day ago
    • Thank you very much Matt. I appreciate this.
    • Geoffresh SEO Web Design

Time to create page: 0.049 seconds