Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9116519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:41:39+00:00 2026-06-17T04:41:39+00:00

Because there isn’t a working plugin for Joomla 2.5 which provides canonical URLs (beside

  • 0

Because there isn’t a working plugin for Joomla 2.5 which provides canonical URLs (beside SEF404), I’ll try to “hack” my template and include a canonical URL when needed.

Because every menu item is accessible with different URL’s and GET-Parameters, I want to include the canonical URL when needed.

I think the easiest solution is to get the URL of the active menu-item and if the accessed url differs to this, then included the canonical-tag into the header (of index.php of the template).

I’ve basic PHP knowledge, but I have no idea how to get the URL of the active menu item and the accessed URL. Can anybody tell me how to get this information? If I have this, then I can simply compare it and if it’s different, add the tag.

Please post some sample code how to get this information.

EDIT: Here is some basic information (only related to the “homepage”), but for me this code doesn’t work. http://writenowdesign.com/joomla-tutorials/joomla-trips-and-tricks/add-canonical-url-link-to-joomla-home-page/

EDIT2: For example:

<?php

// Source: http://www.php.de/php-einsteiger/91123-erledigt-aktuelle-browser-url-ausgeben-funktion-zweckdienlich-2.html
function getUrl($arrAddParam = false, $xhtmlValid = false, $anchor = false, $dropCalledArgs = false) { 

    $url  = !empty($_SERVER['HTTPS']) ? 'https://' : 'http://'; 
    $url .= $_SERVER['SERVER_NAME']; 
    $url .= $_SERVER['SCRIPT_NAME']; 

    // merge input and user param arrays 
    $arrParam = is_array($arrAddParam) ? $arrAddParam : array(); 
    if ($dropCalledArgs === false) $arrParam = array_merge($_GET,$arrParam); 

    if (!empty($arrParam)) { 
        $arg_separator = $xhtmlValid ? '&amp;' : '&'; 
        $url .= "?". http_build_query($arrParam, '', $arg_separator); 
    } 

    // anchor 
    if ($anchor !== false) { 
        $url .= '#'.$anchor; 
    }     

    return $url; 
}

// Get the application object
$app = JFactory::getApplication();
// Get's the menu object
$menu = $app->getMenu();
// Current URL
$activeUrl = getUrl();
// SHOULD get the active menu target as string, but it's an object
// THIS is my question how to get the URL of the current active menu item
$menuUrl = $menu->getActive();

?>

EDIT 3: Here is a possibility to get this url. But I need the SEO url and not the “normal one”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:41:40+00:00Added an answer on June 17, 2026 at 4:41 am

    In the meanwhile I found a solution. Maybe this helps somebody else in my situation:

    <?php
    
    // Get SEO Page URL
    $pageUrl = JURI::current();
    // Get URI Object
    $uri = & JFactory::getURI();
    // Get URI String
    $pageUri = $uri->toString();
    
    // Check if there is a difference
    if ($pageUrl != $pageUri){
        // Insert canonical tag when needed
        echo '<link rel="canonical" href="'.$pageUrl.'" />';
    }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The android sdk won't allow me to install api8 and api10 because there isn't
Well, I know why, it's because there isn't a conversion, but why isn't there
I'm new to PowerShell, but I would like to use it, because there isn't
Automated merging isn't perfect. Just because there isn't a line-edit conflict doesn't mean there
When the command prompt opens and then just closes really fast (because there isn't
I'd like to call a Python function from JavaScript code, because there isn't an
I'm using the standard implementation of the TKCalendar for iOS and because there isn't
WPF is great because there are many ways to achieve your goals. For example,
I can not directly user $('commentbody') because there are many comments and selection needs
I am writing a C program and because there is no string in C,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.