• Resolved ryanchmura

    (@ryanchmura)


    I have a webpage for contact info with tabs along the top for 4 different locations.

    When you click on a different location the contact info on the pages change and the URL updates to add #horizontalTabX (where X is Tab 1-4 accordingly). I am trying to use the GeoIP detection lookup plugin through WP but I am pretty inexperienced with PHP and APIs…

    For testing purposes, I’ve tried to tell it to switch to the AB Tab when it sees my location as BC (where I am testing from).

    The main parts I feel like I am messing up are where it says if ($url = ‘/contact-us’;()) and the switch case to add the #horizontalTab2 onto the contact-us/ URL.

    Any help is greatly appreciated. I am actively going through the documentation but I’m pretty lost.

    add_action(‘template_redirect’, ‘geoip_redirect’, 5);
    function geoip_redirect(){
    if (is_admin())
    return;

    // This condition prevents a redirect loop:
    // Redirect only if the home page is called. Change this condition to the specific page or URL you need.
    if ($url = ‘https://linestar.ca/contact-us/’;())
    return;

    if (!function_exists(‘geoip_detect2_get_info_from_current_ip’))
    return;

    $userInfo = geoip_detect2_get_info_from_current_ip();
    $countryCode = $userInfo->mostSpecificSubdivision->isoCode;
    switch ($countryCode) {
    case ‘BC’:
    $url = ‘contact-us/#horizontalTab2’;
    break;
    case ‘AB’:
    $url = ‘contact-us/#horizontalTab2’;
    break;
    default:
    $url = ”;
    }
    if ($url) {
    wp_redirect(get_site_url(null, $url));
    exit;
    }
    }

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Benjamin Pick

    (@benjamin4)

    It is impossible to set the anchor part (#horizontalTab2) via wp_redirect. You will need to us JS to do this. I would activate the CSS classes in the plugin preferences and then activate the tab according to this class. Simply changing the url to #horizontalTab2 may or may not work, depending on the code that is behind the tabs.

    Sorry if you don’t manage to do this, you will need to find a programmer to do this for you … my plugin is mainly geared at devs.

    Thread Starter ryanchmura

    (@ryanchmura)

    Thanks for the reply! I am also wondering if I am using the correct code to call the info?

    $userInfo = geoip_detect2_get_info_from_current_ip();
    Alert ($userInfo);

    returns nothing D:

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Switch URL element Tab with geolocate?’ is closed to new replies.