Question

I´m building a multi languaje site with Joomla.

At the end of every article it´s shown Social Buttons. I had this piece of code to get current page for the Facebook Like Button.

<?php
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .=   $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
return $pageURL;
}
?>

<div class="fb-like" data-href="<?php echo curPageURL(); ?>" data-width="450" data-show-faces="false" data-send="true"></div>

The problem is: When I build a multilanguage site I get: www.example.com/es and www.example.com/en and when someone click on a social button in one language it dosn´t shows the like in the other language. It´s the same article but with different language, I think it will have the sum of both "like".

For me, the solution is to get the Master Url so...: How can I get the current url widthout language extension(/en and /es) to get a master url?

Was it helpful?

Solution

Try replacing your curPageURL() function with this:

function curPageURL() {

    $url = JURI::current();

    $lang = JFactory::getLanguage();

    $tag = $lang->getTag();

    list($code) = explode("-", $tag);

    $url = str_replace("/" . $code . "/", "/", $url);

    return $url;

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top