WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] I need to deregister some scripts for mobile devices (6 posts)

  1. photocurio
    Member
    Posted 1 year ago #

    I'm trying to make my themes reasonably responsive without creating dedicated mobile themes. I've simply been putting @media CSS at the bottom of my stylesheets. I'm not sure what to do about the javascript though. One javascript (Masonry) messes up the rendering of the site on a phone, and its unnecessary bandwidth.

    My javascripts are loaded in my functions file, using the enqueue script function.

    Can I incorporate an @media conditional into enqueue script? Or is there a better way to do it?

  2. Emil Uzelac
    Theme Review Admin
    Posted 1 year ago #

    Feel free to snoop around my http://wordpress.org/extend/themes/responsive I don't believe that this is needed. All media queries are in a single style.css and IE via respond.js pretty straight-forward solution :)

    Emil

  3. Andrew Bartel
    Member
    Posted 1 year ago #

    Use the PHP Mobile Detect Class and then enqueue which scripts you want depending on the device.

  4. photocurio
    Member
    Posted 1 year ago #

    Andrew, that works, sort of.
    But the code to query to see it its a mobile device is

    if ($detect->isMobile()) {
        // any mobile platform
    }

    What I need is "if its NOT mobile". The obvious if($detect->!isMobile() {} does not work.

  5. photocurio
    Member
    Posted 1 year ago #

    I think I found it:
    ($detect->isMobile() ==false )
    that's the power of trial and error. O and thanks for the tip!

  6. Andrew Bartel
    Member
    Posted 1 year ago #

    I forget not everyone writes php everyday sometimes!

    I'm glad you figured it out. That's really the most rewarding and productive way of approaching programming problems in general.

    $detect->!isMobile() isn't going to work ever, it's not proper php syntax. You don't run the true/false statement on the function call itself. What I think you were trying to do is if(!$detect->isMobile()). What that is essentially saying is: if the result of running isMobile() in the instantiation of $detect is false, or zero, or null, do this. In other programming languages you'll have to be more specific but php will figure it out for you, in this case anyway.

    Your example, if($detect->isMobile() == false) is functionally equivalent to a properly formatted if(!whatever) in php. Hope that helps your future programming in the language.

    Happy coding!

Topic Closed

This topic has been closed to new replies.

About this Topic