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


7

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


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


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


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

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


6

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


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

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


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

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


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

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

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

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

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

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

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

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


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

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

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

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.


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.


2

No, you have to fix the plugin code. Also, send a bug report to the plugin author. I'm sure she wants to improve the plugin.



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