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 trying to register & enqueue ImageMapster in my Skeleton Child Theme on the main.php page to make an image map with hovering image effects. I added this code to the "Header Functions" section of my child theme's functions.php file:

add_action( 'wp_enqueue_scripts', 'load_custom_js' );
function load_custom_js() {
    wp_register_script( 'jquery.imagemapster.js', 
    get_template_directory_uri() . '/javascripts/jquery.imagemapster.js', 
    array('jquery'), '1.2.6', false );

    if ( is_page('Main') ) {
    wp_enqueue_script( 'jquery.imagemapster.js', 
    get_template_directory_uri() . '/javascripts/jquery.imagemapster.js', 
    array('jquery'), '1.2.6', false );
    }
} 

Now my site has ceased to work. The javascript file is located in the parent theme directory, so is it correct to use get_template_directory_uri instead of get_stylesheet_directory_uri? Does each theme have a particular place where one should add custom functions or am I correct in adding it under "Header Functions"? Any help would be appreciated.

share|improve this question
add comment

2 Answers 2

Have you tried using get_template_directory()? This should actually return the parent theme's directory when called from your child theme's functions.php.

Out of curiosity, does the path of your child theme's directory get returned when you're calling get_template_directory_uri right now from your child theme?

share|improve this answer
    
I figured it out - I had accidentally deleted a critical ?> tag from a different function. Everything works fine now. –  jess Oct 2 '12 at 22:36
add comment

One problem: if you define the script in a wp_register_script() like so:

wp_register_script( 
    'jquery.imagemapster.js', 
    get_template_directory_uri() . '/javascripts/jquery.imagemapster.js', 
    array('jquery'), 
    '1.2.6', 
    false 
);

...then you only need to reference the defined script's name in the wp_enqueue_script() call, like so:

wp_enqueue_script( 'jquery.imagemapster.js' );

Re-declaring all of the parameters in wp_enqueue_script() shouldn't cause the fatal error you describe; however, it could cause unintended consequences (especially if the declarations do not match between wp_register_script() and wp_enqueue_script()).

share|improve this answer
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.