Title: Translating links
Last modified: August 21, 2016

---

# Translating links

 *  Resolved [soylug](https://wordpress.org/support/users/soylug/)
 * (@soylug)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/translating-links/)
 * I wonder if there is an easy way to translate links generated by other plugins.
   For example, I’m working with woocommerce and when you add an item to your cart,
   it shows a “View cart” option. Everything is in the language selected, but the“
   VIew cart” button always link to the same page in the same language, although
   I have translated it.
    I was reading I tried with stuff like add_filter(‘pll_the_language_link’,‘
   post_type_link’); but didn’t work. If something like that could work, it will
   be very useful for other plugins. Thanks a lot, your plugin is great!

Viewing 15 replies - 1 through 15 (of 25 total)

1 [2](https://wordpress.org/support/topic/translating-links/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/translating-links/page/2/?output_format=md)

 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/translating-links/#post-4124671)
 * It depends if woocommerce (or other plugins) is applying a filter when generating
   the link.
 * When plugins use WordPress native function such as ‘get_permalink’, ‘get_category_link’…
   this will work out of the box as Polylang of course filters these function.
 * If the link is generated another way, then the plugin has to apply either one
   existing WordPress filter or its own filter. In that last case we need to know
   its name and parameters to add a Polylang filter.
 *  Thread Starter [soylug](https://wordpress.org/support/users/soylug/)
 * (@soylug)
 * [13 years ago](https://wordpress.org/support/topic/translating-links/#post-4124704)
 * First of all, thanks for your answer, nice support!
    This is what I could see:‘
   cart_url’ => get_permalink( woocommerce_get_page_id( ‘cart’ ) ) And the function
   is: ‘function woocommerce_get_page_id( $page ) { $page = apply_filters(‘woocommerce_get_’.
   $page . ‘_page_id’, get_option(‘woocommerce_’ . $page . ‘_page_id’)); return (
   $page ) ? $page : -1; } }’ Do you think it can be solved in an easy way? I’m 
   sorry, I’m not a programmer 🙁 Thanks
 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [13 years ago](https://wordpress.org/support/topic/translating-links/#post-4124719)
 * >  I’m sorry, I’m not a programmer 🙁
 * Not bad if you are not a programmer as you probably found what you need.
 * I suggest that you create a custom plugin. Copy paste the code in texte file 
   you name ‘something.php’. Upload the file in your plugins directory and activate
   the new plugin.
 *     ```
       <?php
       /*
       Plugin Name: Polylang Woocommerce compatibility
       */
   
       if (function_exists('pll_get_post')) { // is Polylang activated?
         add_filter('woocommerce_get_cart_page_id', 'pll_woocommerce_get_cart_page_id');
         function pll_woocommerce_get_cart_page_id($id) {
           return pll_get_post($id); // translate the page to current language
         }
       }
       ```
   
 * This is of course not tested but hopefully it will do what you expect if you 
   translated your cart page.
 *  Thread Starter [soylug](https://wordpress.org/support/users/soylug/)
 * (@soylug)
 * [13 years ago](https://wordpress.org/support/topic/translating-links/#post-4124746)
 * Perfect!! Thanks a lot!! I guess that I can do the same for other pages if I 
   have the same issue.
    Thanks!! ^_^
 *  Thread Starter [soylug](https://wordpress.org/support/users/soylug/)
 * (@soylug)
 * [13 years ago](https://wordpress.org/support/topic/translating-links/#post-4124747)
 * Just one more question (hope last one). NextGEN Gallery plugin can link galleries
   to pages. When calling the link, it allways return the same page in the same 
   language although there is a translation for it. More or less is the same than
   before, but the calling is:
    pageid); ?>”> Can I do something similar? Thanks!
 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [13 years ago](https://wordpress.org/support/topic/translating-links/#post-4124749)
 * Yes you can use pll_get_post for any post, page, custom post. And there is pll_get_term
   for categories, post tags and terms in custom taxonomies.
 *  Thread Starter [soylug](https://wordpress.org/support/users/soylug/)
 * (@soylug)
 * [13 years ago](https://wordpress.org/support/topic/translating-links/#post-4124774)
 * Hi again! Your advices were very useful and I have solved many things doing what
   you told me, but there is a page which I can’t get working and don’t know why!
   
   It’s again about woocommerce plugin, for a page already translated. Is the same
   that I first asked but this time there is something different that I suppose 
   is what is messing things.
 *     ```
       // filter hook for include new pages inside the payment method
       $get_checkout_url = apply_filters( 'woocommerce_get_checkout_url', $woocommerce->cart->get_checkout_url() ); ?>
   
       <form name="checkout" method="post" class="checkout" action="<?php echo esc_url( $get_checkout_url ); ?>">
       ```
   
 * I’ve already added a filter as you said:
 *     ```
       add_filter('woocommerce_get_checkout_url', 'pll_get_checkout_url');
       function pll_get_checkout_url($link) {
           return pll_get_post($link);
       }
       ```
   
 * but doesn’t work, this time it returns main language page. Then, if I change 
   language (clicking on the flag) I get the page in the language selected, so they
   are linked but filter isn’t working.
    Thanks for your help!
 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [13 years ago](https://wordpress.org/support/topic/translating-links/#post-4124778)
 * This can’t work because pll_get_post works with internal page number. And here
   your filter requires an url. Maybe you can post here the code of the function`
   $woocommerce->cart->get_checkout_url()` to see if we can do something with it?
 * I see that you are trying to make Polylang and Woocommerce compatibles. I am 
   sure this would interest a lot of people. Would you like to share the result 
   of your work when it will be completed?
 *  Thread Starter [soylug](https://wordpress.org/support/users/soylug/)
 * (@soylug)
 * [13 years ago](https://wordpress.org/support/topic/translating-links/#post-4124779)
 * Thanks again!
    Here is the code for get_checkout_url:
 *     ```
       /**
       		 * Gets the url to the checkout page.
       		 *
       		 * @return string url to page
       		 */
       		public function get_checkout_url() {
       			$checkout_page_id = woocommerce_get_page_id('checkout');
       			$checkout_url     = '';
       			if ( $checkout_page_id ) {
       				if ( is_ssl() || get_option('woocommerce_force_ssl_checkout') == 'yes' )
       					$checkout_url = str_replace( 'http:', 'https:', get_permalink( $checkout_page_id ) );
       				else
       					$checkout_url = get_permalink( $checkout_page_id );
       			}
       			return apply_filters( 'woocommerce_get_checkout_url', $checkout_url );
       		}
       ```
   
 * I had already thought about sharing results (if I/we manage to get it working).
   As I said I’m not a programmer, so everything I try to change takes a lot of 
   time for me 🙁
    I also used it for nextgen plugin, which I guess is also interesting
   for more people. I’ll share, be sure 😉
 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [13 years ago](https://wordpress.org/support/topic/translating-links/#post-4124780)
 * So here we find the same function ‘woocommerce_get_page_id’ that we already filtered
   previously. So the solution is similar (I simplified it)
 *     ```
       <?php
       /*
       Plugin Name: Polylang Woocommerce compatibility
       */
   
       if (function_exists('pll_get_post')) { // is Polylang activated?
         add_filter('woocommerce_get_cart_page_id', 'pll_get_post');
         add_filter('woocommerce_get_checkout_page_id', 'pll_get_post');
       }
       ```
   
 * You can do this each time you have: `woocommerce_get_page_id('some_page')`
 *  Thread Starter [soylug](https://wordpress.org/support/users/soylug/)
 * (@soylug)
 * [13 years ago](https://wordpress.org/support/topic/translating-links/#post-4124781)
 * Nop, that doesn’t work 🙁
    It does for the cart page, but not for this one…
 *  Thread Starter [soylug](https://wordpress.org/support/users/soylug/)
 * (@soylug)
 * [13 years ago](https://wordpress.org/support/topic/translating-links/#post-4124782)
 * When I say it doesn’t work, I mean that redirects to the same page but appears
   white (doesn’t load). If I comment the “add_filter(‘woocommerce_get_checkout_page_id’,‘
   pll_get_post’);” it returns the page in the main language.
    There is a plugin
   to get woocommerce working with wpml and I downloaded it to have a look in case
   I can find out something I could use, and it uses this function in the filter(
   for cart page, for example):
 *     ```
       function translate_pages_in_settings($id) {
       		return icl_object_id($id, 'page', true);
       	}
       ```
   
 * I saw on your web that this is as pll_get_post. But for checkout page, their 
   function is this one:
 *     ```
       function get_checkout_page_url(){
               return get_permalink(icl_object_id(get_option('woocommerce_checkout_page_id'), 'page', true));
           }
       ```
   
 * I’m telling this just in case you can see a solution
    Thanks a lot
 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [13 years ago](https://wordpress.org/support/topic/translating-links/#post-4124783)
 * The WPML version should work as is as Polylang includes some WPML function (including
   icl_object_id) 🙂
 * The pure Polylang version would look like:
 *     ```
       function get_checkout_page_url(){
         return get_permalink(pll_get_post(get_option('woocommerce_checkout_page_id')));
       }
       ```
   
 * I guess there is somewhere something like
 *     ```
       add_filter('woocommerce_get_checkout_url', 'get_checkout_page_url');
       ```
   
 *  Thread Starter [soylug](https://wordpress.org/support/users/soylug/)
 * (@soylug)
 * [13 years ago](https://wordpress.org/support/topic/translating-links/#post-4124785)
 * I’m stuck with this 🙁
    What I’m trying to do now is this:
 *     ```
       add_filter ('woocommerce_get_checkout_url', 'redirect_checkout_page_translated');
       function redirect_checkout_page_translated() {
       	$page_id = get_page_by_title('checkout');
       	$page_id_lan = pll_get_post ($page_id);
       	$url = get_permalink ($page_id_lan);
       	return $url;
         }
       ```
   
 * but doesn’t work… If I don’t use pll_get_post, just this:
 *     ```
       add_filter ('woocommerce_get_checkout_url', 'redirect_checkout_page_translated');
       function redirect_checkout_page_translated() {
       	$page_id = get_page_by_title('checkout');
       	$url = get_permalink ($page_id);
       	return $url;
         }
       ```
   
 * it redirects ok (I have try with several posts). I had understood that pll_get_post
   function works with ids, so it should work… or not?
 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [13 years ago](https://wordpress.org/support/topic/translating-links/#post-4124786)
 * It’s strange that the second works as [get_page_by_title](http://codex.wordpress.org/Function_Reference/get_page_by_title)
   does not return the page ID but a page object.
    So you should do:
 *     ```
       $page = get_page_by_title('checkout');
       $page_id_lan = pll_get_post ($page->ID);
       $url = get_permalink ($page_id_lan);
       ```
   

Viewing 15 replies - 1 through 15 (of 25 total)

1 [2](https://wordpress.org/support/topic/translating-links/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/translating-links/page/2/?output_format=md)

 The topic ‘Translating links’ is closed to new replies.

 * ![](https://ps.w.org/polylang/assets/icon-256x256.png?rev=3433336)
 * [Polylang](https://wordpress.org/plugins/polylang/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/polylang/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/polylang/)
 * [Active Topics](https://wordpress.org/support/plugin/polylang/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/polylang/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/polylang/reviews/)

 * 25 replies
 * 4 participants
 * Last reply from: [miteran](https://wordpress.org/support/users/miteran/)
 * Last activity: [12 years, 1 month ago](https://wordpress.org/support/topic/translating-links/page/2/#post-4124853)
 * Status: resolved