0

I need to hide the branding section of my blog, but only when someone is viewing it from the iPad. I am not sure how to attack this.

EDIT: the function remove_access currently works in my template, but I need to add the iPad function.

So would this look correct for trying to hide the area:

<?php 
function remove_access() {
 if(is_page(array(63, 386, 391, 405, 'forums'))) {
    remove_action('thematic_header','thematic_blogtitle',3);
    remove_action('thematic_header', 'thematic_blogdescription',5);
    remove_action('thematic_header', 'thematic_brandingclosing',7);
    remove_action('thematic_header','thematic_access',9);
    remove_action('thematic_footer','thematic_siteinfoopen',20);
    remove_action('thematic_footer','thematic_siteinfo',30);
  }
}
if( preg_match('/ipad/i',$_SERVER['HTTP_USER_AGENT']) ){
    add_action('template_redirect', 'remove_access');
}

EDIT-3:

the complete function

changed the condition to: if (it's an iPad AND page is blog) OR (if it's one of the pages in array), then remove items.

<?php
function remove_access() {
    if( preg_match('/ipad/i',$_SERVER['HTTP_USER_AGENT']) && is_page('blog') || is_page(array(63, 386, 391, 405, 'forums')) ){
        remove_action('thematic_header','thematic_blogtitle',3);
        remove_action('thematic_header', 'thematic_blogdescription',5);
        remove_action('thematic_header', 'thematic_brandingclosing',7);
        remove_action('thematic_header','thematic_access',9);
        remove_action('thematic_footer','thematic_siteinfoopen',20);
        remove_action('thematic_footer','thematic_siteinfo',30);
    }
}

add_action('template_redirect', 'remove_access');

EDIT-4:

Add a function to remove from child pages as well. I tried this, but it doesn't seem to work:

function remove_access() {
if( preg_match('/ipad/i',$_SERVER['HTTP_USER_AGENT']) && is_page('blog') && ($post->post_parent == 'blog') || is_page(array(63, 386, 391, 405, 'forums')) && ($post->post_parent == (63, 386, 391, 405, 'forums')) ){
    remove_action('thematic_header','thematic_blogtitle',3);
    remove_action('thematic_header', 'thematic_blogdescription',5);
    remove_action('thematic_header', 'thematic_brandingclosing',7);
    remove_action('thematic_header','thematic_access',9);
    remove_action('thematic_footer','thematic_siteinfoopen',20);
    remove_action('thematic_footer','thematic_siteinfo',30);
  }
}

add_action('template_redirect', 'remove_access');
5
  • I'm a bit confused. you want to remove those things if it's one of the listed pages OR an iPad?
    – Milo
    Commented Jun 23, 2011 at 16:26
  • Both. I need those areas to be hidden because they are only being accessed through an iPad app. The original function works fine because I don't have actual links on the website to access them. However, the blog is accessible from both the website navigation and the iPad app. I don't want those areas to display if the user is using an iPad. Hopefully I am clear, I have a tendency to be too vague sometimes...
    – chris_s
    Commented Jun 23, 2011 at 16:30
  • I edited your code, see if I understood you correctly.
    – Milo
    Commented Jun 23, 2011 at 17:23
  • Perfect, I knew there was a way to combine them. I just wasn't piecing it together in my head. That's a huge help. Thank you!
    – chris_s
    Commented Jun 23, 2011 at 17:28
  • Here's another question for you. actions are removed from those pages, however, it seems the child pages still show those areas. How can I hide those areas if they are child pages as well?
    – chris_s
    Commented Jun 23, 2011 at 17:36

2 Answers 2

3

there's no foolproof method for doing this, but a quick and simple solution is to look at http user agent:

<?php
if( preg_match('/ipad/i',$_SERVER['HTTP_USER_AGENT']) ):
    echo "is iPad";
endif;
2
  • So would this look correct for trying to hide the area:
    – chris_s
    Commented Jun 23, 2011 at 15:58
  • @chris_s - edited your code to fix the if() statement. if(): endif; is just a newer alternate syntax of if(){ }. I also moved it to check around the add_action, but I suppose you could do it either way.
    – Milo
    Commented Jun 23, 2011 at 16:13
0

You want to use the WURFL, which is a constantly-updated, open-source device description repository. Follow these instructions to set up the API on your Wordpress install, and then you'll be able to query the WURFL database for "WURFL ID: apple_ipad_ver1"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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