I have some users coming in from a fixed IP range on a very slow connection (256kbps) so want to server them a child theme that has a lot of the bandwidth intensive features removed. For ease of management/maintanability a child theme is preferred to a seperate theme.

I have setup a plugin so I can detect IP, and trigger:

add_action('setup_theme', 'switch_user_theme');
function switch_user_theme() {
    $ip = $_SERVER['REMOTE_ADDR'];
    if ( $ip == 'x.x.x.x' ) {
         $user_theme = 'baspresslite';
         add_filter( 'template', create_function( '$t', 'return "' . $user_theme . '";' ) );
         add_filter( 'stylesheet', create_function( '$s', 'return "' . $user_theme . '";' ) );

This works fine for switching users to a seperate theme, but not to a child theme as a child theme needs to also call files from the parent theme - it seems these filters basically do a rewrite on all requests.

How can this be achieved? Are there alternative filters / actions to hook in to? Or maybe a rewrite action in .htaccess that says if you try to load a file and it isn't found then try this alternative path replacing the child theme name with the parent theme (potential redirect loop here though)?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.