• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Conditional Code to Run Depending on Display Resolution

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Conditional Code to Run Depending on Display Resolution

This topic is: resolved

Tagged: conditional, functions.php, mobile first, php

  • This topic has 3 replies, 2 voices, and was last updated 8 years, 4 months ago by Brad Dalton.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • September 26, 2014 at 4:42 am #125804
    neilmac
    Member

    Hi, does anyone know how to do this?

    I would like to run code via functions.php depending on the display resolution.

    For example, if I use Brian Gardner's new mobile first theme I might want to show a slider only on displays above 800px wide.

    I don't want to set display:none in the CSS for the slider at lower resolutions as that would defeat the point of a mobile first theme. The slider code would only run at higher resolutions.

    I know there is a plugin which adds a body class for the device it thinks the user is on. Maybe I could use some sort of conditional code based on a displayed desktop class. If so, how would I do that?

    I don't know of a plugin to add a body class for display resolutions or even if that would be the answer to my problem.

    Thanks

    September 26, 2014 at 10:34 pm #125902
    Brad Dalton
    Participant

    You could try and add a custom body class using the wp_is_mobile conditional tag


    Get Help – Book Consultation.

    September 27, 2014 at 3:17 pm #126006
    neilmac
    Member

    Thanks Brad.
    Thing out loud, maybe I don't need to add a body class if I use wp_is_mobile.
    If I used something like if ( !wp_is_mobile() ) perhaps I could add some code to a hook which would only work on desktop displays - or at least larger than tablet. Which is the behaviour I want.
    Would that work? Or is it a bad idea for any reason?
    Thanks

    September 27, 2014 at 3:38 pm #126010
    Brad Dalton
    Participant

    Give it a try and see how you go.


    Get Help – Book Consultation.

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble