If you want to get the language of the browser do so:
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
If you want to redirect to ?lang=en
:
header("location: {$_SERVER['REQUEST_URI']}?lang={$lang}");
You should read about HTTP_ACCEPT_LANGAUGE.
There are many ways you can dance with languages but you should understand some key points.
- Chose the default language of your website (French in your case)
- The user may be French but his OS & Browser can be in English because he wants to learn the language of trade.
- Create a cookie that stores the selected (or default) language so that you know what content to display.
$_COOKIE["wpse_166976_lang"] = "fr"
or$_COOKIE["wpse_166976_lang"] = $land
where$lang = get_query_var("lang")
To get the language with WPML plugin, you could use ICL_LANGUAGE_CODE
to get the language of the page
Related Posts:
- Show the most popular post per week
- why is translation not working on theme?
- How to change date language without changing the entire site language?
- Filter the blog title displayed in the header
- How to change
- php syntax – how to concatenate properly – echo bloginfo(‘stylesheet_directory)
- How to let users change site language?
- Non-Closing PHP Query in WordPress Loop
- Split site title and apply different classes
- Using bloginfo and divs inside a php file
- WordPress language switcher doesn’t work
- Changing wordpress default language
- How to set base url for php widget
- CSS images don’t show up with bloginfo
- Implementing a multilingual WordPress site by installing several instances of WordPress and redirecting
- I have a background-image in css file but don’t show in site.how to fix this prblm. i sent screenshot. thx
- Change WooCommerce currency programmatically on AJAX request
- How to display dual language menus and headers?
- How to Get Linked Elements for a specific ml_source_elementid
- Conditionally change WordPress core language
- Multilanguage website on two different domains
- How can I include a file related to blog URL? Nothing seems to work
- WPMU – How to echo only one URL
- How to translate the blog date in the Avada theme [closed]
- Display current category title on category page
- How to get the custom header image’s alt text?
- PHP unit testing WordPress?
- WordPress GET parameters causing 404 Not Found
- is_page() not working from within a plugin
- How to create custom php script page
- Metabox repeating fields – radio buttons not saving correctly
- Create WordPress pages with PHP
- How do i hide the if the appears
- How to return the_excerpt (without echo)?
- How to handle a custom form in wordpress to submit to another page?
- Replacing mysql_real_escape_string in WordPress theme
- TCPDF get_post_meta outside the loop
- Database “Migration” for Plugins?
- WooCommerce Link to Product Category
- Easiest way to show total number of subpages
- using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
- ACF check if variable has http, if else return string
- Can’t load WP function into external function
- Woocommerce – Filter Variable Products by Variation Attributes and Variations Regular Price
- Loading header.php on specific page
- Adding a div at the bottom of a sidebar
- How can I set a default category for a custom post type in wordpress?
- Sort posts by custom fields value using dropdown menu
- how do I get a specific post from a post with a subcategory in WP
- PHP Fatal error: Out of memory in WordPress [closed]
- Theme developement – incative sidebars
- add_cap not working
- Weird 404 URL Problem – domain name being placed at end of urls
- Styling my own password protected page, how to deal with wrong password?
- Where is wp() function definition?
- WordPress add_rewrite_rules for custom URLs ending in .html
- How to make modifications only to certain elements of an HTML string on the server-side?
- How does WordPress interpret the php code?
- How to execute html code inside php?
- WordPress get_media_embedded
- After adding my website to a new server, I keep getting a unexpected end of file error, but the file is identitcal to it’s original source
- Add editor toolbar to Metabox
- Include js script ONLY on woocommerce product category pages? [closed]
- How to hide specific categories from contributors
- PHP $_REQUEST array empty
- how to enqueque code in a php file from functions.php
- How to get all the items of a taxonomy even if it does not have a custom post type?
- Displaying Overlay images over thumbnail of category type?
- Strip hashtag off permalink with php
- Uses for function: wp_update_user
- How can I add diffrent editable text fields?
- How can I check if a post with a particular slug or title exists?
- How do I integrate vanilla Javascript to a wordpress website?
- I want to retrieve the email or username data entered for password reset, but failed. how can I do it?
- Exclude category from function – PHP
- ACF – Can’t get custom post type by taxonomy
- Update user meta when an external link in admin notice is clicked
- Is there an option to execute javascript file only on plugin activation
- update_post_meta Not Processing Array Data (Not Sure What I Am Missing)
- WordPress randomly redirects with 301 after logging in
- How to count posts posts if they are in a separate content page?
- Ajax in a class instantiated via shortcode
- append data to mysql table via submit button coded in php – not working
- When working with a post, almost all wp_postmeta are deleted
- How to tell if a page has subpages for Custom Post Types
- Why transition_post_type hook is called twice for the same post?
- How to do a MySql query in WordPress?
- “Page Array” displaying in title bar on Front Page
- Facebook like update status for wordpress
- Custom Taxonomy Link Text Echo Name Not Slug
- Find trigger behind occasional php undefined error
- Permission error on plugin save
- Restricting Post Content Visibility with Custom Code – where to put it?
- Adding Gravity Form With if(is_page) Is Not Working
- Implement “No related posts for this entry” into the loop?
- Twig+WordPress how to use array arguments inside a function?
- I would like to alert message while another user is editing or update data in wordpress admin panel, what should i do?
- How to lock users account until approvation
- WooCommerce: write featured image dimensions to custom fields in product’
- transition_post_status hook, works – but not if the post is new