MyBB Community Forums

Full Version: Use a separate theme for mobile?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello and thank you in advance for the help.
I am wanting to be able to detect screen size (perhaps with javascript screen.width <= 800 for example) and I want to be able to have it use a different theme based upon this.
A few things:
1) I am not opposed to running a separate installation for example one mybb in root / and one in /mobile if that is something that can easily be done.
2) PLEASE do not suggest ways of "using mobile themes." Respectfully I have searched and searched and we simply cannot find a theme that fits both the desktop and mobile/responsive needs. Separate themes are a must.
3) It is also possible for a user to be using a laptop, then jump on their phone, then back to laptop for example so this solution needs to work easily flipping based upon screen size.

I have tried this in the header:
<script type="text/javascript">
	const queryString = window.location.search;
	const urlParams = new URLSearchParams(queryString);	
   <!--
   if (screen.width <= 800 && urlParams.get('theme') != 3) {
       window.location = "https://example.com/?theme=3";
   } else if(screen.width > 800 && urlParams.get('theme') != 7) {
	   window.location = "https://example/com/?theme=7";  
   }
   //-->
</script>






I then modified global.php as:

//if(isset($mybb->input['theme']) && verify_post_check($mybb->get_input('my_post_key'), true))
if(isset($mybb->input['theme'])) {
	if($mybb->input['theme'] == '3' || $mybb->input['theme'] == '7') {


That bypassed the verify_post_check which likely wasn't smart but I was working on a concept to build on.
The above solution kind of works, except users cannot then navigate the site without a redirection each time it loads, and a check is needed on every page (could come from bookmark etc)

So what I am needing to do is basically:
Any time that any page loads, check if the screen size is > 800 (800 not important, just a number for now) and based upon that set the theme for that page load. Can anyone help me and tell me how to do this?

It would also be nice not to rely on javascript as some people disable it, but that is only a bonus.
You can try GoMobile plugin, by itself it has a theme for mybb but maybe outdated. Only you will need the plugin and the installation, at that point go to options on the plugin and select the theme ID for GoMobile and done !

That should be more easy due the system will detect the device and set the theme in that case.

I was removed some options in an old repo but as always people put bad references so i decide to remove it, but you can find it here for sure and customize it at your owns Smile

https://community.mybb.com/mods.php?action=view&pid=331

By the way i found a versions in here for 1.8
Thank you for the reply. I will look into that, but it seems like a theme itself. Sorry, I was a bit unclear at first, I already have themes picked out and setup, installed, etc. My struggle is getting the right size routed to them (small screen to small theme and regular to regular). Is there not a way to intercept between the page load and the screen size to determine which theme to use?

I was able to get it sorted. Thank you! Smile