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 still looking for a solution for this and can't seem to find it. I have the following code to start, but am not sure how to write the function to fire off a .js file. I need this to work on one specific page ID.

function ipad_alert() {
 if( preg_match('/ipad/i',$_SERVER['HTTP_USER_AGENT'])) {?>
      // link to .js file? 
 <?php }
 }
 add_action('init','ipad_alert');
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

use wp_enqueue_script() to add a js file. I've hooked wp_enqueue_scripts so I can check is_page() for a specific page.

function ipad_alert() {
    if( preg_match('/ipad/i',$_SERVER['HTTP_USER_AGENT']) && is_page(7) ) {
        wp_enqueue_script('my_script', get_bloginfo('template_directory') . '/js/my_script.js');
    }
}
add_action('wp_enqueue_scripts','ipad_alert');
share|improve this answer
    
I've tried using that, but I can't seem to get it to work. Here's a knucklehead question. I currently have the HTML that the js is supposed to hook to in the wordpress editor. Could that keep it from working? I didn't know create a specific template page for this because I don't see the need. –  chris_s Jul 19 '11 at 20:10
    
@chris_s - I'm not sure I understand what you mean? I put the above code in my functions.php file and it's working, so I'm not sure what the issue may be without more info. –  Milo Jul 22 '11 at 19:22
    
I currently have this HTML in the editor in a page. <a href="#dialog" name="modal">Simple Modal Window</a> <div id="boxes"> <!-- #customize your modal window here --> <div id="dialog" class="window"> <b>Testing of Modal Window</b> <!-- close button is defined as close class --> <a href="#" class="close">Close it</a> </div> <!-- Do not remove div#mask, because you'll need it to fill the whole screen --> <div id="mask"></div> </div> Can I get this to work if it's in the editor? –  chris_s Jul 26 '11 at 19:51
add comment

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.