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 need to add the following JS to the head, but I don't know how to add the "data-cfasync="false" " by using "wp_register_script" or "wp_enqueue_scripts". Please help!!

<script data-cfasync="false" type="text/javascript" src="http://use.typekit.com/YOUR-KIT-ID.js"></script>
<script data-cfasync="false" type="text/javascript">try{Typekit.load();}catch(e){}</script>
share|improve this question
2  
Your question is similar to: wordpress.stackexchange.com/questions/38319/… The answer there will cover your question. –  Pontus Abrahamsson Jul 23 '12 at 10:42

1 Answer 1

up vote 0 down vote accepted

If you need to add it in the head, then this might help you:

<?php
add_action('wp_head', 'add_attr');
function add_attr(){
    ?>
        <script data-cfasync="false" type="text/javascript" src="http://use.typekit.com/YOUR-KIT-ID.js"></script>
        <script data-cfasync="false" type="text/javascript">try{Typekit.load();}catch(e){}</script>
    <?php
}
?>

Make sure your theme has the wp_head function call. You'll need wp_enqueue_scripts or wp_register_scripts only if your JS code in in some other .js file and you need to call it on some page.

share|improve this answer
    
Should I place this code to the 'header.php' file in the 'themes' folder? If yes, which area should I place this code in? –  RRN Jul 23 '12 at 11:31
    
@RRN paste the code in the functions.php of your theme –  Tribalpixel Jul 23 '12 at 12:29
    
thanks, by the way, does it mean "wp_enqueue_scripts" should only be used when I need the JS on some page but not all?? –  RRN Jul 23 '12 at 15:55
    
Nope... it means when your js code is in a separate .js file and you want to use it, for a specific or all pages. It runs on all the pages but using conditional tags, you can restrict it to the pages you want. –  Rutwick Gangurde Jul 24 '12 at 5:33
    
Ok, so why I should not use "wp_enqueue_scripts" for the current situation? Thanks. –  RRN Jul 24 '12 at 16:43

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.