Tag Info

Hot answers tagged

17

Like most others, I highly recommend using WPTouch. However, it's built more to support blogs than other website formats, so I know it's not the panacea of mobile solutions (I run my portfolio on WordPress as well as my blog, and my portfolio looks like **** in WPTouch). So I did take a look at the code to find the relevant portions that you'd need to use ...


14

When WordPress activates a plugin, it calls the activate_plugin() function. This function activates the plugin in a sandbox and redirects somewhere else on success. It's been used by a few authors to programmatically activate plugin dependencies. There's another function, deactivate_plugin(), that does a similar thing in reverse ... it's actually how ...


10

Yes it works well. It's a very simple function but never found a mobile device not recognized by it. It recognize the 90%+ of mobile devices. Main difference from mobiledetect.net is that doesn't differe from phone and tablets. See the code


9

I would have done it as following, I am sure experts here will have a better way but following is what I could come up with in hurry. First create your controller file in your theme directory (or any other if you like) with the following content. For this example the file name is korkmaz.php UPDATE 1: Please replace the previous korkmaz.php because ...


8

Step 1: Define two custom image sizes, e.g.: <?php add_image_size( 'normal-thumbnail', 400, 300, false ); // Default image size add_image_size( 'mobile-device-thumbnail', 200, 150, false ); // Mobile-device image size ?> Step 2: Implement your chosen means to determine client. There are several ways, and which method you use is outside the scope ...


8

t f's answer got me thinking. Actually, I can use the core function and adapt it as I like but just put everything in a new function. So here goes: function my_wp_is_mobile() { static $is_mobile; if ( isset($is_mobile) ) return $is_mobile; if ( empty($_SERVER['HTTP_USER_AGENT']) ) { $is_mobile = false; } elseif ( ...


7

This is thanks to EAMann's brilliant answer above, and I thought it might be helpful to the original poster too... I needed a solution to make sure users deactivated my plugin if they uploaded the premium version (to avoid potential conflicts). Previously I detected its state with is_plugin_active and showed an admin error message to prompt users to switch ...


7

At the risk of not answering the question, I'd advise to not do so. I've been using iOS devices for months, and one of the first things I did back when I bought my iPad was to try to come up with CSS layout that changed its behavior based on the device used (and, originally, the screen orientation). At the time of writing, it's running on my dev site ...


7

You might want to look at how the very popular WPtouch plugin does this. It gives a different theme for "iPhone, iPod touch, Android, Opera Mini, Palm Pre, Samsung touch and BlackBerry Storm/Torch mobile devices". I see a list of user agents in their source code, that's probably the key. Another plugin, WP-Wurfled, uses the extensive Wireless Universal ...


6

I personally use the WP Touch plugin on my site. It automatically detects if the user is browsing with an iPhone (or iPad) and reformats the site into an iOS-friendly layout with touch-sensitive controls. There's an option at the bottom for visitors to display the normal site if they want. It's a very well-supported system, and I've used it on 3 of my own ...


6

Ok, you want that mobile devices always load mobile templates. Desktop devices load template files based on resolution: if < 1080 mobile ones, > 1080 desktop ones. Your workflow should be: On init you check for mobile devices using wp_is_mobile. If true you add a template filter that returns str_replace('.php', '-mobile.php', $template); where ...


6

TL;DR Yes, WordPress can certainly act as a backend for a mobile app. Yes, a page can act as a rest endpoint / interface. No, a theme template is not the right territory for the logic. Write your own plugin. Pointers I find it hard to believe that no one else has done this. I, for one, have. More than once. And I'm near certain I'm not alone. "No ...


5

In very layman term wp_is_mobile() is not for styling your theme. How it works: It matches some of device's native name in User Agent String. So if someone manipulate the string and send false information you can not detect what device it is. And it does not return any device name it just return true if you are on not on desktop else false How WordPress ...


5

something like this maybe: function my_class_names($classes) { $useragent = $_SERVER['HTTP_USER_AGENT']; if(strchr($useragent,'Safari')) $classes[] = 'Safari'; // etc.. return $classes; } add_filter('body_class','my_class_names'); Edit - as per Chip's suggestion, here's the function using the WordPress useragents checks: function ...


5

You can use the built in function wp_is_mobile() Override a style with wp_enqueue_style add_action('wp_enqueue_scripts', 'my_mobile_styles'); function my_mobile_styles(){ if(wp_is_mobile()){ wp_register_style( 'my-mobile-style', 'URL_to_stylesheet', array('id-of-main-stylesheet') ); wp_enqueue_style( 'my-mobile-style' ); } } ...


4

My child theme inlcudes php as well as css files. Whenever I switch to a different theme for mobile browsers it works but the custom post types, cats etc are missing in action. I am kind of lost. Your problem is that you're doing too much with the theme. Themes are all about presentation, not about functionality. If your child or parent theme is ...


4

WordPress is a set of PHP scripts running on a web server. So your application needs a web server, a data base and PHP. I don’t think this is possible on all of those platforms.


4

You misunderstand mechanics of how theme works. It does have index.php template, but request is still processed by WordPress main index.php in site's root. It makes no sense to redirect visitor to theme's folder because themes are not meant to be visited directly (they expect WP core to be loaded for them and such). I am not proficient with such plugins, ...


4

I had exactly the same problem. In the base TwentyTwelve theme there has been a code change so that the site navigation changed from h3 to button. You need to update header.php file in the child theme to use <button class="menu-toggle"><?php _e( 'Menu', 'twentytwelve' ); ?></button> See WordPress TRAC #28824 comment 13 The problem ...


4

I do think that the days of creating a separate theme for mobile users are long gone. With proper planning and layout you can use one theme on desktops, laptops, tablets and mobile devices I would tackle this is a much different way. Firstly, I would create my theme in such a way it is responsive on according to the required screensize like normal. For ...


3

For the record, I'm not sure why anyone would use the JetPack JSON API as it currently works for a self hosted site. If you're doing AJAX and JSON, the whole point is to get back some JSON data FAST. Using jetpack involves an unnecessary call to wordpress.com, which then does a call to your own self hosted blog. Using the wonderful JSON API plugin, you ...


3

Create 2 menus. One for display on mobiles and one as a default for desktops. Add this code in your header.php or you could use a hook in your functions file. <?php if ( wp_is_mobile() ) { wp_nav_menu( array( 'theme_location' => 'mobile-menu' ) ); } else { wp_nav_menu( array( 'theme_location' => 'desktop-menu' ) ); } ?> Or you could ...


3

You can have a subdomain, but you cannot detect mobile users reliably. And you shouldn’t. How to use a subdomain with the same content In your wp-config.php, look at $_SERVER['HTTP_HOST']. If it matches m.example.com, enforce the current domain as main domain with … const DOMAIN_CURRENT_SITE = 'm.example.com'; … and filter the active theme: ...


3

global variables are not a good solution Yes, I heard this sentence a lot of times, but as you experienced, sometimes some variables need to be accessed everywhere. Some modern PHP frameworks implement advanced patterns like IOC that helps in such type of things, but wordpress lacks in that, and this is the reason a lot of global variables is used in ...


3

Personally I always tend to stick to using responsive design rather than a completely different theme. You then will only have theme to keep updated. Check out this article for more information http://www.techrepublic.com/blog/webmaster/how-to-get-started-with-responsive-web-design/1769


3

Yes. Using CSS won't prevent JS from loading generally but it's more reliable than server side sniffing. Depends on project but I would go with media queries to just hide it or bring it in page's content flow. @media (max-width: 768px) { .sticky-social { display: none; } }


3

There is wp_is_mobile() function to conditionally display (or block) content for mobile users. <?php if (!wp_is_mobile()) : ?> <!-- Stuff to hide from mobile users --> <?php endif; ?>


3

While s_ha_dum's answer is not only not wrong, but exactly the answer you'd expect to get, I'd highly advise against using it, whether you are on 3.4+ or not. User agent sniffing sucks. Whether done manually or via a core function. Period. For one, new UA strings pop up like wildfire. For another, a good number of browsers pretend to be something else ...


3

Hi @Hamza: I think what you are looking to do is for your plugin to hook 'template_include' to tell it to load a file from your plugin directory. Here's starter code for your plugin: <?php /* Plugin Name: Mobile View Plugin */ if (is_mobile_user()) // YOU NEED TO DEFINE THIS FUNCTION class MobileViewPlugin { static function on_load() { ...


3

Wordpress Mobile pack plugin does the exact job you want http://wordpress.org/extend/plugins/wordpress-mobile-pack/ you can choose different theme for mobile users you are provided with some specially made for phones themes to choose from no hassle - no bugs



Only top voted, non community-wiki answers of a minimum length are eligible