You need to check that you aren’t already on the mobile site:
function redirecting_to_mobile_site() {
if ( $_SERVER['SERVER_NAME'] !== 'm.example.com' && wp_is_mobile() ) {
wp_redirect( 'http://m.example.com' . $_SERVER['REQUEST_URI'], 301 );
exit;
}
}
add_action( 'template_redirect', 'redirecting_to_mobile_site' );
You’ll need to clear your browser cache to properly test the fix.
Related Posts:
- Check if add_menu_page exists or not
- Can Not Redirect from Plugin-Registered Admin Page
- Redirect to a welcome page after updating plugin
- WordPress Redirect Not Working – AJAX Callback Response Not Picked Up
- Redirecting thousands of posts that currently have no category in their permalink when changing permalink structure to include category
- wp_redirect() Error in Custom Plugin
- External Domain on WordPress Multisite
- Subdomains with almost the same content
- Howto check version of another plugin and then add a submenu page to it
- How to use add_submenu_page() for editors?
- Installing wordpress on a subdomain of an already existing static website
- How can I redirect some pages to new subdomain? [closed]
- wp_redirect doen’t work
- Notice: Undefined index: mtral_field_subscriber
- wp_redirect not working on plugin
- Adding submenu to custom plugin menu page created with add_menu_page() function
- Redirect plugin after form submit or show errors
- How to Call Specific .PHP file on add_submenu_page selection in Plugin Development?
- In a WPMU that uses several different domains, how to enable users to register subdomains of any domain from the main site?
- How to hide plugin submenu title in drop down in admin panel in wordpress?
- How to add styles to a submenu page?
- Woocommerce redirection if no previous orders
- Is it possible to have permalinks to sub-domain pages and to root pages within one single WP instance?
- Crazy redirect happening with no redirects set up
- Submenu Page under Settings in Admin Panel
- Admin menu hilighting wrong item for CPT
- redirect to a custom page
- How to make wp multisite subdomain exist search
- Plugin with AJAX on subdomains causes 404 in console
- Specific plugin script not working on subdomain
- Clone a Post Tite and Custom Field into Custom Post type
- How do I secure a subdomain using UCC SSL?
- How to remove post redirects
- Multiple plugins settings of same developer into ONE settings page linked together
- How to disable core and plugin updates
- Consuming an external API in WordPress?
- Is there a plugin for posting inline comments, like in MS Word? [closed]
- Plugin “Add from server” not working when selection a large number of medias
- Does plugin uninstall always put WordPress back into original state?
- How to Loop Plugin Option Field Set?
- How can I list only sites that use a particular theme or plugin?
- Can I ignore caching of a plugin in W3 Total Cache? [closed]
- Plugin for Sending Email to Readers about New Posts? (besides “Subscribe2 “)
- Create plugin that works in background
- Checking for user role in a custom plugin
- Advanced Integration – WordPress + YOURLS
- Extend Elementor Archive Posts widget with a custom skin in order to show multiple badges
- Automatically translating from existing .po and .mo files?
- jQuery function didn’t work in my plugin
- Should WordPress plugins adhere to WordPress admin panel styling?
- How can we deal with unmaintained plugins with vulnerabilities?
- Adding json as params to shortcode
- adding meta data using plugin to top of head
- How to make Http Request to a php file present in plugin directory of wordpress
- How to checkout the wordpress.org plugin repository?
- Plugin to host auctions on your site
- How can I add Expire headers to images?
- Inserting above the comment template
- All Users > User List > Update User Meta Field Inline
- List Category Posts rewrite necessitates rewrite of customised templates
- Moving Share Buttons from a Plugin
- How do I create a filter feature on WordPress? [closed]
- Plugin: register_deactivation_hook works perfectly well, while register_activation_hook suddenly stopped working
- Load external images via proxy
- Ability to automatically redirect a URL
- Passing Page ID used in Meta Box Creation to JavaScript
- How to Add Custom New Published Post Counter Icon on Top of the WordPress Site [closed]
- Co-Authors Plugin Displaying Wrong Author
- How to pass variables to a function argument using add_action [duplicate]
- Identifying where plugins are being used in your wordpress install
- update_option_{$option} not showing old value
- How to get the particular product quantity in orders in Woocommerce [closed]
- Tutor LMS problem with Paid Memberships Pro [closed]
- A server-side hook failed when committing plugin code to SVN
- Update WP option by plugin
- plugin enqueue style on all pages
- File Uploader – Upload without adding to Media Library
- Table appears in Visual mode of editor but not in preview or after publish
- Do WordPress plugins suport multisite site?
- Any gallery plugins that allow commenting on single images?
- How To Use do_shortcode with WooCommerce One Page Checkout
- Displaying page content from plugin, inside exising empty WP page
- Update widget values from ajax function
- how can export data in excel file custom plugin
- dbDelta not CREATING TABLE
- wp_mail in pluggable.php return path original settings
- How to put a maximum real-time users limit
- How to exclude a part of a page in search results
- Custom admin plugin read CSV
- plugin installing error
- Get custom term link archive with prefix
- Plugin, add opengraph tags after form submit
- How woo-commerce store Product Data value in DB?
- Creating a page that does not show up in the frontend navigation bar
- Plugin constructor called multiple times
- how to call jQuery in admin as well as in homepage
- How to programmatically detect how many posts are displayed per page?
- Is a custom post type considred a plugin?
- Migrate DB Plugin: Error “The directory needs to be writable”
- Woocommerce disable checkout on specific day