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.

I am trying to add a stylesheet when users are accessing the blog section of my site from and iPad. The first snippet of code works, however, I don't want to use the absolute path. I want to use wordpress's function.

function ipad_css() {
  if( preg_match('/ipad/i',$_SERVER['HTTP_USER_AGENT'])) {?>
<link rel="stylesheet" type="text/css" href="http://website/wp-content/themes/my_theme/ipad.css" media="screen" /> 
<?php }
  }
  add_action('init','ipad_css');

This doesn't seem to work:

function ipad_css() {
  if( preg_match('/ipad/i',$_SERVER['HTTP_USER_AGENT'])) {?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/ipad.css" media="screen" /> 
<?php }
  }
  add_action('init','ipad_css');

I'm confused as to why it won't work. I have trying stylesheet_url as well with no luck.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Try replacing <?php bloginfo('template_directory'); ?> with <?php echo get_template_directory_uri(); ?>

Also, I wouldn't hook it to the initaction, why don't use wp_print_styles instead? It is a style after all.

share|improve this answer
    
I tried this method and it's still not working. I can't for the life of me figure it out. –  chris_s Jul 28 '11 at 16:05
    
well I did figure it out. instead of using get_template_directory_uri() I used get_stylesheet_directory_uri because I am using a child theme. –  chris_s Jul 28 '11 at 19:51

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.