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"] = $landwhere$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]
- make my custom theme support polylang plugin
- Insert attributes names according to language with polylang programmatically
- How to filter custom taxonomy term name, slug, and description?
- An audio player that showcase a random song from playlist every 24h [closed]
- how to prevent wordpress admin from logging in via woocommerce my-account page
- get_the_ID() in the footer returns wrong value
- Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
- Trouble inputting variable into WP query
- How to get the last category name of a child category?
- Add html link in functions.php files of the theme
- How can I add a UTM tag with PHP code to pick up the post slug dynamically in the UTM?
- How do I include SVG file used as featured image?
- Use value from Ajax call in PHP function
- require_once() if a product in woocommerce contains a tag [closed]
- the_posts_pagination() not working in wpquery
- Automatic excerpt is not shown with the_excerpt() command
- Using ob_start and ob_get_clean with wordpress shortcode
- Change “No Comments” link to “My String” on Blog Post (Find Snippet in Code or use CSS, PHP Solution) [closed]
- Return product description
- How to add the sidebar to all the pages except the home page? [closed]
- Header not properly displaying on archive.php
- Custom meta box values are not getting saved for my custom post type
- Get the last 5 products from each category
- How to say if meta_value is greater than 0 in an array?
- Getting users with a specific meta data and then querying their posts?
- Why does the post_type_link hook everything twice?
- Adding a tag_ID column into Categories inside the admin dashboard?
- How to pass a variable into an add_filter() function?
- locale filter function running multiple times
- Multiple requests external data api dynamic block gutenberg
- Why does the Woocommerce grouped template prints the unpublished products?
- Woocommerce with Lazy Load php and ajax
- Adding conditional text to a PHP Shortcode Template
- How do I get the content excerpt of the recent post?
- How to check $_GET isset for a parameter and value? [closed]
- How to deal with too many $_POST variable conditions from ajax request at backend? [closed]
- Making your own custom post views count
- Save Custom CSS file in the upload folder dynamically?
- How to use two meta_compare in an array?
- How to update and save user metadata on page visits?
- Verify if a category is the child of another category
- How to remap one of the TinyMCE Advanced Editor button to open the wordpress media library?
- Simple AJAX notification when the new post is added to the database
- How to optimize update_post_meta?
- Warning: in_array() null given in PHP function
- Contact Form 7 – Replace database configured form template with a static file
- AJAX wp_insert_user WORKS but responds with “The site is not enabled”
- Why can’t I return a value from $wpdb->get var?
- How to get User Time Zone in WordPress?
- How to hook a logout funtion for specific usr role in wordpress?
- Redirection after submitting duplicate comment
- Convert code – not work
- Fix error Gravatar alt
- HTML Special Characters in URL string [closed]
- how to save checkbox data for custom setting?
- How to remove sidebar primary widget on Mobile on category page [closed]
- How to keep the capability of users and disable Gutenberg editor in WordPress?
- Upload multiple files in randomly generated folder using wp_upload_bits
- Is it possible to change content in my PHP file from WordPress dashboard
- ACF put a comma after the last repeater field value [closed]
- Create page template via functions.php?
- Loading two post layouts for the same post with different url
- Code snippet to show current php version inside “At a Glance” box in admin
- parsing nested blocks (in columns, etc) via PHP
- Show ACF field with link to ultimate member profile/WordPress user profile below the post (single post layout)
- getting url from variable that calls picture of current page, not working. Only displays everything instead of url
- How to upload WP user avatar on woocommerce account page [closed]
- Use post ID in functions.php file adminside
- How to show childs of certain custom post type in option list?
- Short code template + ajax
- str_replace with the_content is not working
- How do I populate custom field with current user role in Woocommerce [closed]
- WPML best page selector with php
- How to disable send e-mail notification new comments for some posts
- trying to put an active hover to my custom nav category buttons [closed]
- How to edit HTML of my website on WordPress? [closed]