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'm new to wordpress and programming in general. For my first site there is a custom template in which I want to load a javascript library. After registering and enqueueing it in functions.php my site no longer loads properly. I'm sure what it is simple mistake and would really appreciate a little help. For the record, I'm using a child theme of twentytwelve.

Here is the code:

<?php 
function load_wforms() {  
    if (is_page(45)) {  
        wp_register_script('wforms', get_stylesheet_directory_uri().'/js/wforms.js'), false, '2.0');  
        wp_enqueue_script('wforms');  
    }  
}  
add_action('init', 'wforms');  
?>

Thanks!

share|improve this question

closed as too localized by brasofilo, s_ha_dum, Wyck, toscho Feb 16 '13 at 7:31

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
there's an extra parenthesis here: '/js/wforms.js'). enable debugging so you can see php errors. –  Milo Feb 16 '13 at 2:07
    
Thanks Milo, I'll be sure to keep a better eye out in the future. –  cellsuicide Feb 16 '13 at 2:16
    
Actually, I don't think this question is too localized. The issue of not naming the callback function the same as the second add_action() parameter is one that many people (and probably all of us here) have made. –  Chip Bennett Feb 16 '13 at 12:16

1 Answer 1

up vote 1 down vote accepted

First, be sure to enable WP_DEBUG in your wp-config.php file, so that you can see fatal error messages.

In this case, the problem is that you've named your function load_wforms(), but you reference the callback wforms in your add_action() call:

function load_wforms() {}  

...vs...

add_action('init', 'wforms'); 

The second parameter, wforms, refers to a function named wforms() - but your function is named load_wforms(). Change your add_action to this:

add_action( 'init', 'load_wforms' );

(Side note: you should enqueue scripts at wp_enqueue_scripts, rather than init.)

Edit

Also: fix the syntax error as noted by @milo in his comment:

wp_register_script('wforms', get_stylesheet_directory_uri().'/js/wforms.js'), false, '2.0');

You have an extra parenthesis:

'/js/wforms.js')

...should be:

'/js/wforms.js'
share|improve this answer
    
Thanks Chip! I'm sorry for bringing you down to my level on this one...I guess we all have to start somewhere. –  cellsuicide Feb 16 '13 at 2:13

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