I am building a mobile friendly plugin and put the theme directory inside the plugin directory.
If it’s a mobile browser, how can I redirect to the theme in the plugin directory?
/wp-content/plugins/mobview/theme/
I’ve managed to use the following redirection:
wp_redirect( plugins_url('/mobview/theme/index.php') );
exit ;
But am kind of lost in the directory redirect inside WordPress structure.
Hi @Hamza:
I think what you are looking to do is for your plugin to hook
'template_include'
to tell it to load a file from your plugin directory. Here’s starter code for your plugin:Of course this will require that you somehow filter out when it is not a mobile user by defining the
is_mobile_user()
function (or similar) and it also means that your/theme/index.php
will need to handle everything, included all URLs as you’ve basically bypassed the default URL routing by doing this (or your could inspect the values oftemplate_file
and reuse the logic by routing to equivalent files in your plugin directory.) Good luck.P.S. This does not provide a mobile solution for the admin. That would be 10x more involved.
You misunderstand mechanics of how theme works. It does have
index.php
template, but request is still processed by WordPress mainindex.php
in site’s root. It makes no sense to redirect visitor to theme’s folder because themes are not meant to be visited directly (they expect WP core to be loaded for them and such).I am not proficient with such plugins, but I imagine they are likely using
template_redirect
hook to load their templates instead of those of active theme on match to mobile browser.I think they are quite a few plugins on this topic in official repository, you can look through their code to get an ideas for common techniques used.
if i am not wrong then
try this code
$includes_path = TEMPLATEPATH . '/your folder name/';
then write this
require_once ($includes_path . 'file name');
well ,
i think , i mis-explained my question , thu i explained more in the sub-comments :
All i needed is : to activate another theme , in different directory , and to do such thing
first :
register the new theme directory :
register_theme_directory( WP_PLUGIN_DIR . '/mobview/theme' )
;2nd :
to add a filter to use this theme :
Now all i need to do is to select if the browser is a mobile or not then activate the action .
Thank you .
update :
this is the answer to my first question up . Thank you 🙂