logo

$10
WPML echo url that switches to the correct url on translation

Hi

I've run into an issue with WMPL plugin.

I have various links hard coded into my theme.


<a href="<?php bloginfo('url'); ?>/riders" title="" class="button white-black pie ">
<?php _e('view the riders page','my theme'); ?>
</a>


If I switch to another language, and then click this button, I get a 404. For example if I was viewing Spanish, the URL would need to be...
<?php bloginfo('url'); ?>/jinetes/?lang=es


But when I switch language, the link does not change.

I read this documentation...

http://wpml.org/documentation/support/creating-multilingual-wordpress-themes/hard-coded-theme-links/

...and this bascially says you can only output full a tags, which is not what I'm after. I after just the URL.

I don't want to start messing with my css to accomodate these links by using
<?php icl_link_to_element(10); ?>
I need to just echo the URL string.

Thanks

Josh Cranwell | 01/27/12 at 8:38pm | Edit

Previous versions of this question: 01/27/12 at 8:40pm

(1) Possible Answers Submitted...

  • avatar
    Last edited:
    01/27/12
    11:27pm
    Christianto says:

    Hi,

    You can use icl_object_id to return id of the page, if you supply it with permalink you can use this function, please try:

    function get_permalink_tp_wpml($permalink = '', $lang = 'es', $id = '', $post_type = ''){

    if(!empty($permalink)){
    $target_id = url_to_postid($permalink);
    } else {
    $target_id = $id;
    }

    if(empty($post_type)){
    $post_type = get_post_type($target_id);
    }

    if($target_id){
    $lang_id = icl_object_id( $target_id, $post_type, true, $lang);
    return get_permalink($lang_id);
    }
    return $permalink;
    }


    and called it with url to be change as parameter for example get_bloginfo('url').'/riders'

    echo get_permalink_tp_wpml( get_bloginfo('url').'/riders');


    Or you can pass id and post type.

    Btw, off topic, Have you tried my code on your question here?
    could you try it, because this day is the last day before the prize goes to community pot, and tomorrow you cannot vote anymore. Hope you don't mind to try it..

    Thanks

    • 01/27/12 11:31pm

      Josh Cranwell says:

      Hi Christianto,

      Thanks for this I will have ago in 2 secs

      Also on that question, tomorrow is the evening I will be testing your code. So I will be in touch for sure :-)

    • 01/28/12 12:08am

      Josh Cranwell says:

      I got to go to bed, I will check this out tomorrow. THanks

    • 01/28/12 12:12am

      Christianto says:

      Ok, have a nice dream, enjoy it.. ;-)

    • 01/28/12 10:47am

      Josh Cranwell says:

      I managed to get it to work with this...

      <?php $permalink = get_permalink( icl_object_id(20, 'page', false) ); echo $permalink ?>

This question has expired.



idt, Josh Cranwell, Francisco Javier Carazo Gil voted on this question.



Current status of this question: Completed