WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
W3TC conflict with mobile redirect plugin | PHP header() (9 posts)

  1. kiddhustle
    Member
    Posted 1 year ago #

    Hi there

    I am developing a plugin for a user of your plugin but it seems to be conflicting with the re-direct functionality (i.e. mobile users are not being redirected) which uses a PHP header('Location: http://www.example.com') redirect.

    I am using the 'template_redirect' action hook (have also tried the wp_head hook) but it doesn't work when your plugin is activated.

    Could you advise where might be a better place (or action hook) to run the redirect code so that the plugin can redirect to another site before your plugin kicks in?

    I can send you my plugin if if helps.

    Here's the hook I am using:

    add_action('template_redirect', 'redirect_user', 0 );

    http://wordpress.org/extend/plugins/w3-total-cache/

  2. Frederick Townes
    Member
    Plugin Author

    Posted 1 year ago #

    When PHP isn't loaded, redirects won't work. So any page caching will interfere with your implementation. W3TC has user agent groups that allow you to pass requests to respective themes or URLs if you want.

  3. calliewallie
    Member
    Posted 1 year ago #

    Hi there, I am having the same issue. When I am using a mobile detection script to redirect mobile users to a mobile compatible URL, it deactivates when W3Total Cache is active. Any workaround for this?

  4. JochenT
    Member
    Posted 1 year ago #

    Go to topic "User Agent Groups" and click on "Create a group". Select the theme you want to use for your mobile or fill "Redirect users to".

    At "User agents" enter the agent names of the mobiles to use (e.g. ipad). Spaces and special characters have to be escaped with backslashes! See the other agent names for examples.

    Move your new group to the top.

  5. Frederick Townes
    Member
    Plugin Author

    Posted 1 year ago #

    @JochenT, clearly you mean that this worked for you?

  6. kiddhustle
    Member
    Posted 1 year ago #

    Hi I remember looking over this recently.

    A colleague has since taken over the project, but I think in my case changing the action hook to: parse_query (maybe send_headers) would have solved my problem. My colleague implemented an .htaccess solution outside of WordPress so never had a chance to try it personally.

    Yes using the user agent groups should work in W3TC but there are other caching plugins that will overwrite/cancel the redirect..

    Like I said I am no longer on the project but my guess is that this is the right place to to detect the user agent and redirect and because the you should be able to detect the user agent and no headers should have been sent yet.

    If you get a chance to try this please let me know, could come in handy in the future.

  7. JochenT
    Member
    Posted 1 year ago #

    @Frederick, yes I use this method to manage two caches for the same theme.

    The reason was a code snippet in the WP header template which adjusts some sizes for the ipad.

    If a redirect to another URL is calculated in the script, I think "-- Pass-through --" should be selected and "Redirect users to" should be empty.

    Sorry, my answer was intended for @calliewallie, not the original question.

  8. calliewallie
    Member
    Posted 1 year ago #

    Thanks @JochenT I have tried:

    Group name: 1.High
    Enabled: (checked)
    Theme: Pass-Through
    Redirect Users to: (blank)
    User Agents: smartphone

    and it doesn't work...? I've also tried with 'Redirect users to" with the mobile url in place and can't get it working. Any other suggestions? Thanks in advance :)

  9. Frederick Townes
    Member
    Plugin Author

    Posted 1 year ago #

    I'm working with the developer to address this.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic