MyBB Community Forums

Full Version: get screen width using php in template
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello master of mybb and spacial php masters..

i am already use Template Conditionals mybb plugin and try to make 
<if content usign screen width but its'nt work properly.
<if window.screen.width <= 680 then> You are using mobile device</if>

 <if window.screen.width >= 680 then> You are using computer</if>

but itsn't work please fix this issue.
Because that's javascript, not PHP. Use javascript to hide and show a div, PHP conditionals aren't what you want here.
yes i can make js screen width resolution but have one problem js only hide display on screen not completely remove all coding around with this script.
and page will be going long loading...
i want make full optimse template with responsive layout using php and remove extra coding completely in mobile resolution to make faster page load.

if its n't available in PHP conditionals so please give me php coding for globle.php and for other .php file to geting screen width using $mybb->['screen.with'] vreb.

i now this vreb not work i want same php coding to get work this vreb and geting sreen width then i will easily do this.

<if $mybb->['screen.with'] <= 680 then> You are using mobile device</if>

 <if $mybb->['screen.with'] >= 680 then> You are using computer</if>


<if 480 <= 680 then> You are using mobile device</if>

 <if 1020 >= 680 then> You are using computer</if>
With my theme variables premium plugin, there is code to determine if a user is browsing on a mobile device. You can parse separate content for mobile devices and desktop devices. For more info, you can see my services thread in my signature.
You're not going to get reliable screen size metrics in PHP - PHP is executed server side, screen width is client side. You're using the wrong technology to achieve this, what you really want are CSS media queries.
I already use CSS media method.

But really want most optimization template just need screen width then I will do.

And how to use theme variables plugin?
So you're trying to optimise the site by removing a few lines of HTML for certain screen sizes? My advice would be it's really not worth it, there will be absolutely no benefit whatsoever on the scale you're doing it, you'll be saving literally a few bytes of data. If you're that worried about it, put your site behind Cloudflare so it will minify the HTML for you.