Search code examples
wordpressmultilingualpermalinks

wordpress get current permalink or url without domain


I'm not sure if I titled this correctly but this is my issue, I have to create 2 same exact blogs and the only difference is language. So but what I need is at the top when clicked on a language it would take the user to that same page but in the language he/she clicked on.

I'm using permalinks currently and I've tried the following:

<?php 
   function my_permalink() {
    echo substr(get_permalink(), strlen(get_option('home')));
   }

   my_permalink();
?>

but that for some reason on my home page points to a post and not the home page. I believe that works in posts but I need that to also work on the home. Here's the links to both blogs, any help is much appreciated..

English: http://www.inblu.pe/prblog/ Spanish: http://www.inblu.pe/prbloges/


Solution

  • It could be more simple with standard PHP method :

    $_SERVER["REQUEST_URI"]
    

    Of course it will work for current post only.

    You can also use that :

    <?php 
       function my_permalink() {
        echo substr(get_permalink(), strlen(home_url('/')));
       }
    
       my_permalink();
    ?>