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
- Image crop, resize and compression plugin?
- I want to know about the plugins that help in while I write code on my Page? [closed]
- How to Include File from Plugins into Template?
- How to prevent plugins from sniffing/stealing other plugins’ options?
- Fetch Data from other website in wordpress (screen scraping)
- Allowing users to Sign-up > Login > Post articles that need approval
- What is a good plugin for making a template that can be reused to make several objects on a single page?
- Is there a plugin for feedback like Kissmetrics available? [closed]
- adding a button to the media uploader
- Hotel reservation plugin you would recommend [closed]
- how to insert a HTML form into a javascript popup?
- Mask and Track Outbound Links
- Get path to themes CSS file inside of a Plugin
- Shortcode does not expand in Facebook like
- How can I modify page content in the admin panel?
- Is there a plugin to turn comments into structured reviews [closed]
- how to activate a plugin inside a theme
- WordPress programming video tutorials [closed]
- Add Content to Content()
- WordPress front end AJAX. Return 0 :?
- Add some fileds to the wp_posts table
- Hook for page Request?
- Check if user is on backend page
- rewrite_rules() not applying rules on plugin activation only after permalinks menu is clicked
- How to Resize the Custom Post Images?
- WordPress stats: OWA plugin overhead in the future
- Flag Comment as inappropriate button plugin
- Display a consistent Google Plus icon on ALL pages of my site
- Custom Login Page — wp_signon Headers Already Sent?
- Display Plugin Panels Outside of Admin Areas
- Editing wp-config.php
- How to display terms and conditions in post area?
- Is there a function to list all uploaded images? How can I add one?
- Plugin that will let me specify a number of image sizes?
- How to edit a published post?
- breadcrumb need to show all pages and subpages
- What are the correct permissions so WP doesn’t ask for FTP credentials if installing plugin?
- Widget’s container?
- MediaElement.js works on one site but not the other?
- Customizing Titles on the Fly with Code
- Tools for styling code snippet in a web page
- wp_enqueue_style for plugin options page
- Popular Post With Thumbnail?
- Moving to a WordPress blog. What do I need to know?
- WP-nivo-slider Producing Error “Cannot modify header information – headers already sent by …”
- Is changing post from category in a large blog a good practice?
- How to keep track of new plugins published on wordpress.org?
- Contact Form 7 – Show image on successful send? [closed]
- Is this a plug-in in wordpress or a custom JavaScript
- What is generating Similar Posts and Related Posts on my blog?
- Default plugin config to override wp_options?
- Performance impact with inactive plugins? [duplicate]
- Best portfolio/gallery/carousel slideshow plugin with thickbox? [closed]
- Disable plugin only for one post
- Placing the two most voted posts at the top (in a WordPress site that uses the Vote it up plugin)?
- Is there any plugin which enables users to rate comments in thumbs up-down way?
- custom uploader in the admin area
- Plugin Repostitory Questions
- Timed content and flagging content as viewed by user?
- How do I add the same contact form to multiple wordpress sites and capture the response in one place or database?
- eLearning Module
- Add SideBar/Widgets Just Below the Post
- Amazon.com intergration with WordPress?
- How to best create a jQuery Slider to display a native wordpress gallery?
- Free paypal cart solution [closed]
- Best/Correct way to add an option to a category