/*
Theme Name:           Flatsome
Theme URI:            http://flatsome.uxthemes.com
Author:               UX-Themes
Author URI:           https://uxthemes.com
Description:          Multi-Purpose Responsive WooCommerce Theme
Version:              3.17.1
Requires at least:    5.4.0
Requires PHP:         5.6.20
WC requires at least: 4.7.0
Text Domain:          flatsome
License:              https://themeforest.net/licenses
License URI:          https://themeforest.net/licenses
*/


/***************
All custom CSS should be added to Flatsome > Advanced > Custom CSS,
or in the style.css of a Child Theme.
***************/
add_action('wp_head', function () {
    if ( is_front_page() ) {
        $base_url  = home_url('/');
        $vi_vn_url = home_url('/vi-vn/');
        echo "\n\t" . '<link rel="shortlink" href="' . esc_url($base_url) . '" />';
        echo "\n\t" . '<link rel="canonical" href="' . esc_url($vi_vn_url) . '" />' . "\n";
        echo "\t" . '<link rel="alternate" hreflang="vi" href="' . esc_url($vi_vn_url) . '" />' . "\n";
        echo "\t" . '<link rel="alternate" hreflang="vi-vn" href="' . esc_url($vi_vn_url) . '" />' . "\n";
    }
}, 1);
add_action('init', function () {
    $path = untrailingslashit(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));

    if ($path === '/vi-vn') {
        define('IS_VI_VN', true);
        $_SERVER['REQUEST_URI'] = '/';
        $_GET = [];
    }
});

add_filter('rank_math/frontend/canonical', function($canonical) {
    if (is_front_page()) {
        return false;
    }
    return $canonical;
});