• 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

Help Detecting Mobile User & then Using Alternate Javascript in a Text Widget

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 › Design Tips and Tricks › Help Detecting Mobile User & then Using Alternate Javascript in a Text Widget

This topic is: not resolved

Tagged: mobile responsive ads

  • This topic has 1 reply, 2 voices, and was last updated 12 years, 1 month ago by Tony @ AlphaBlossom.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • September 17, 2014 at 4:52 pm #124822
    sirraj
    Member

    Hey!

    I am using a text widget (html/script pasted below) to run a banner ad in the Right Header space and it's working great on desktop. However, when I view it on mobile it's a disaster and I'm left with a horizontally scrolling responsive site because the ad is too wide.

    I need to figure out how to put a conditional statement in the text widget (or somewhere else) that allows me to use a different ad script when the user is on a mobile device.

    I'm a novice, so some detailed instructions could help. I found some info on using conditional statements in wordpress( http://clicknathan.com/web-design/wordpress-mobile-conditional-statement/) but not sure if this will solve the problem or how to implement it.

    Many Thanks,

    Sirraj

    I'm using Magazine Pro child theme:

    AD SCRIPT
    <div id='div-gpt-ad-xxxxxxxxxxxx' style='width:728px; height:90px;'>
    <script type='text/javascript'>
    googletag.cmd.push(function() { googletag.display('div-gpt-ad-xxxxxxxxxxxxxx'); });
    </script>
    </div>

    https://gomonsoon.com/chronicle/
    September 17, 2014 at 10:43 pm #124849
    Tony @ AlphaBlossom
    Member

    Hello,

    Wordpress had a function wp_is_mobile that you can use:

    http://codex.wordpress.org/Function_Reference/wp_is_mobile

    Note that this is very broad...an iphone is considered mobile, and an ipad is also considered mobile.

    You would use it something like this:

    
    if ( wp_is_mobile() ) {
         // your mobile code goes here
    } else {
         // your non-mobile code goes here
    }
    

    If you want to ad it to your widget areas, you can use a plugin that lets you execute php code inside of a text widget, our you can add this function to your theme's functions.php file:

    http://www.carriedils.com/extend-wordpress-widgets-without-plugin/

    If you want to target devices more specifically, you can use the article you posted (just adjust your conditionals to match), or take a look at the Mobble plugin (I haven't used it yet but plan to try it soon):

    https://wordpress.org/plugins/mobble/faq/

    That should get you going in the right direction.

    Tony


    Tony Eppright | http://www.AlphaBlossom.com | Follow me on twitter @_alphablossom

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Design Tips and Tricks’ 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

© 2026 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