It’s pretty hard for PHP to know your screen width. It’s more of a job for jQuery. But your approach seems kind of backward. If the site is supposed to be responsive — why are you trying to deliver different pages to your visitors based on screen width?
It would seem you should handle varying content via media queries.
So if you have 5 pieces of content… let’s say
-
Header A – intended for desktop
-
Header B – intended for mobile
-
Content – same for all
-
Footer A – intended for desktop
-
Footer B – intended for mobile
You would hide the mobile (B) components when screen width is greater than X, and show the desktop (A) components.
Conversely, when screen width is less than X, you would do the opposite: showing mobile components (B) and hiding desktop components (A).
Make sense?
Related Posts:
- pass object/JSON to wp_localize_script
- What is the best practice for customizing a plugin’s JavaScript/jQuery?
- How to Change CSS Variable value in Theme Customizer Live Preview
- How to correctly add JQuery in a WP theme?
- Including Javascript options
- jQuery not available to other scripts
- How to: JQuery multiple wordpress media uploader buttons in the same options page?
- My jQuery is enqueued properly. So why isn’t it working?
- How to enqueue scripts properly with ES6 webpack?
- change background image on scroll
- How would I get this to work – send to post from thick box
- FitVid not working for iframes on particular theme install
- Theme now uses require.js and enqueue script no longer works
- can’t add EVENT LISTENER to a element
- jQuery Snippet Not Working on WordPress Site [closed]
- WP Customizer get control value on change
- Execute javscript when theme customizer loads (autosave issue)
- Does the functions.php file ever get called during an AJAX call? Debug AJAX
- theme path in javascript file
- How to include jQuery and JavaScript files correctly?
- Solutions for generating dynamic javascript / CSS
- How can I set image sizes and still have responsive images using the srcset attribute?
- Proper, exhaustive documentation for wp.editor etc
- Any alternate TinyMCE4 themes / subthemes?
- jQuery in header or footer
- Trigger Customizer saving process with Javascript only
- Excess White Space Above Admin Bar on Frontend Using Twitter Bootstrap
- How to Add a .js file Only in one specific Page Dynamically to Head
- Featured Image in 4.4 should be larger on mobile device
- How to use the responsive images feature from WP 4.4 in your themes
- How do I “unhook” / de-register jQuery so that it’s not called as part of wp_footer();?
- Changing the entire control choices using wp.customize with JavaScript
- Check javascript file Proper way in functions.php
- WordPress Google Maps in Custom Theme
- Modifying JS files in Child-theme
- wp_enqueue_script being ignored in custom theme
- Whats the safest way to output custom JavaScript and Css code entered by the admin in the Theme Settings?
- WordPress Customizer Control with React
- Getting jquery to work with custom theme
- How to configure wordpress to work with Vuejs with SSR and without hashbang
- Adding wp_enqueue_media(); causes problem
- Toggle Sidebar Display
- Fancy-box Esay wordpress plugin fails to work on Multilingual site
- Meta tag viewport
- Can’t show custom post thumbnail sizes as background images
- How to make wordpress theme iframe responsive
- JavaScript Change focus to password field login page being reset
- How to make Isotope and WordPress work together?
- Single page site with history.js
- Implementing FancyBox
- How to add material design css in wordpress and woocommerce
- Theme Javascript.php Overwritten Nightly [closed]
- Menu jumping when calling it via PHP
- Responsive Images – crop don’t seem to work
- How to get javascript slider to work! [closed]
- Post thumbnail to append post content via ajax click event
- Would to use AJAX to get an option from the database and use it in a jquery setup or is there an alternative to consider?
- Using page-id-{ID} from body_class() in local dev, versus live staging
- Custom theme, contact form 7 & fast secure form doesn’t work
- Custom image size vs CSS sizing
- Change Responsive Images Maximum Width of 1600px
- Javascipt issue on custom theme
- wp_enqueue_script not working?
- White screen when attaching css to function.php
- WordPress theme resource won’t load over VPN
- pass wordpress template directory into ajax url call
- theme-independent CSS/JS files
- jQuery from parent theme loaded with many other scripts in a single min.js file
- Javascript development in Custom Themes
- How do I implement jPanelMenu?
- loading javascript after jquery is loaded
- getBoundingClientRect() showing different values on load vs scroll
- wordpress script_loader_tag in function.php
- How to diagnose wp-env environment problem
- how can i remove js file from my footer in wordpress
- Cannot collapse a responsive menu in WordPress
- How to properly use AWS SES for a contact form?
- Ajax Comment Upvotes – Votes don’t always register
- add class to all images inside the content
- Customizer Image-Picker Preview Not Working
- how to add jquery to wordpress
- Flexslider not working for my custom theme WordPress
- Theme customizer live preview JS- Trying to bind to an html image url without luck
- Can’t attach Javascript to theme
- enqueue script if page is not equal to
- wp_deregister_script was called incorrectly
- Using wp_enqueue_script with social media buttons?
- How to convert that page to a wordpress template? [closed]
- wp_enqueue_script causes page to vanish
- WordPress Subpages Fancybox Trouble
- How to reuse parts of WordPress site e.g. header, footer, part of header for multiple WordPress sites?
- How to resize video lightbox popup in wordpress? [closed]
- Elementor Pro and Astra have different breakpoints – how to salvage?
- Javascript as Jquery Function Call?
- WP site makes mobile browser crash for high memory usage
- Correct way to make a custom block theme responsive
- How to get the value entered in the input field in wordpres
- How react js and other Javascript Technologies works on WordPress plugin?
- How do I work with responsive images in WordPress? (img srcset/sizes)
- Is there any halfway decent documentation on the wp.media JS class?