Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Since the Ipad doesn't work nicely with issuu I'm trying to set up a system where if users would acces one of my blog post from an ipad device they get redirected to the a pdf file which is on my server.

For this I'm guessing I would have to include some kind of HTML code at the beginning of each post. However I'm not familiar with HTML. Is it possible to redirect visitors from my wordpress blog based on their browser (safari) or device (iPad)?

It tried this but it didn't work:

<!--[if safari]> <a href="http://blog.united-academics.org/wp-content/uploads/2011/04/Food-hunger.pdf" target="_blank">HTML Help</a><![endif]-->

Hope you guys can help!

share|improve this question

3 Answers 3

A quick Google shows up with this

There's 2 ways you can do this:

  1. Detect the user agent with JavaScript and redirect
  2. Detect the user agent server-side and redirect

With JavaScript you'd modify the code on the page linked above, with PHP you'd compare $_SERVER['HTTP_USER_AGENT'] to whatever the user agent of iPads contain.

share|improve this answer

The ipad has a user-agent string;

Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us)
AppleWebKit/531.21.10 (KHTML, like Gecko) 
Version/4.0.4 Mobile/7B334b Safari/531.21.10

You can detect and re-direct the user-agent in your header or at the server level.(these examples are for iPad only not iPhone or safari).

PHP:

$isiPad = strpos( $_SERVER[ 'HTTP_USER_AGENT' ],'iPad' ) !== false;

.htaccess:

RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
RewriteRule ^(.*)$ http://whateverurlyouwant.example.com [R=301]

Javascript:

var isiPad = navigator.userAgent.match(/iPad/i) != null;

Media Query:

media="only screen and (max-device-width: 1024px)"
share|improve this answer

You can use the plugin mobble and this plugin will give you access to the function is_ipad()

so:

if(is_ipad()) {
    // do redirect
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.