WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How do I get only dynamic part of the URL? (2 posts)

  1. lynneness
    Member
    Posted 6 years ago #

    I am doing a localization of some site that is using WordPress, and I'd like to have URL listed in page template so that two language enter-links with each other.

    For example, we have:
    http://site_url.com/<dynamic link>
    for English site, and
    http://site_url.com/jp/<dynamic link>
    for Japanese site.

    The website is mostly consist of Pages and not Posts. I cannot use page ID since the main site (English) has different page IDs than Japanese ones. All the pages have parent page + page slug.

    I'm sure there is some syntax to just get the <dynamic links> part, but I just cannot find it.

    Thanks in advance!

    ps. Sadly, language switcher is not an option, since... the site admin doesn't want to use it :S

  2. lynneness
    Member
    Posted 6 years ago #

    If anyone's interested, this is what I'm end up inserting into Page Template:

    English->Japanese

    <p align=right><a href="http://site_url.com/jp
    <?php
    echo $_SERVER["REQUEST_URI"];
    ?>
    ">日本語</a></p>

    where current URL is http://site_url.com/dynamic/link/ and output is http://site_url.com/jp/dynamic/link/

    Japanese->English

    <p align=right><a href="http://site_url.com/
    <?php
    $str = $_SERVER["REQUEST_URI"];
    $array = explode("/", $str, 3);
    echo $array[2];
    ?>
    ">English</a></p>

    where current URL is http://site_url.com/jp/dynamic/link/ and the output is http://site_url.com/dynamic/link/

    ps. We have two separate WP software installed, one in the root, the other in /jp/ folder.

Topic Closed

This topic has been closed to new replies.

About this Topic