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 ...


16

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 ...


14

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


12

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 ...


10

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 ...


9

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 ...


9

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 ( ...


9

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 ...


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 (http:...


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

Yes, the wp_is_mobile() works well, but you can run into problems when using aggressive caching systems, such as fastcgi, proxy cache, etc. that skip the php execution. If that is the case, I would recomend some client side (javascript) detection method that is loaded for both mobile and desktop browsers.


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 $...


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' ); } } ...


5

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 ...


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

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 defining ...


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

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 ...


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 ...


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

Official page: http://windowsphone.wordpress.org/ Was kinda hard to find, I basically guessed URL in few tries in analogy to android.wordpress.org :)


3

Simple: Use the wp_is_mobile() to test - it will trigger true for all mobile devices (smart phones, tablets, etc.). Update Please do not do that. It does not work reliable.


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


3

try to read this useful article: http://digwp.com/2009/12/redirect-mobile-users-to-mobile-theme/


3

Yes, there are a few - did you search for them? Here are the top results from Google: WPTouch Carrington Mobile WordPress Mobile Pack


3

To build the theme in itself i'd recommend you jQuery Mobile. I've already used it for a few wordpress mobile sites, work great. You can then use a plugin like WPtap Mobile Detector to automatically redirect the mobile users to the mobile theme that you've created. This will let them navigate with the same urls as desktop version but through the mobile ...


3

Just wrap you code up in a conditional: if ( $GLOBALS['is_iphone'] ) { // do funky stuff for mini screens } global $is_iphone; will trigger TRUE for all mobile devices incl. tablets. Edit for WP 3.4+ Now there's wp_is_mobile() to make checks for User-Agent. It's basically a wrapper for $is_iphone and does the same.



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