Register and enqueue Hype scripts in WordPress

wordpress

(Rick Wolff) #1

The maker of a WordPress theme that clearly already incorporates JavaScript has suggested that I enqueue the script. The format for such an edit to functions.php appears in this article in TutsPlus.
So here’s what I’m trying:

<?php 
function load_hype() {
    wp_register_script( 'woofhomepage_hype_generated_script.js', content_url('/woofhomepage.hyperesources/woofhomepage_hype_generated_script.js').'/HYPE-526.full.min.js'__FILE__) );
    wp_enqueue_script('woofhomepage_hype_generated_script.js');
}
add_action('init', 'load_hype');
?>

…and it’s crashing the whole site.
Any clue what I’m doing wrong?
Here’s the site in question, at which I’ve returned a default photo and h1.


#2

Try this, I’m not 100% on enqueing in Wordpress.

<?php
function load_hype() {
    wp_register_script('my_script', content_url('/woofhomepage.hyperesources/woofhomepage_hype_generated_script.js', __FILE__), false);

    wp_enqueue_script('my_script');
}
add_action( 'wp_enqueue_scripts', 'load_hype' ); 

?>

I noticed some discrepancies in your code: i.e missing comma and not adding true or false (before footer or in header respectively)


(Rick Wolff) #3

It’s not working. What’s another approach? I’m all out of options.


#4

It looks like there’s a couple 404 errors on that page: http://woof-music.com/wp-content/woofhomepage.hyperesources/woofhomepage_hype_generated_script.js?ver=4.5.1

[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (woofhomepage_hype_generated_script.js, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (HYPE-526.thin.min.js, line 0)

If this doesn’t work, you can always make this a part of your theme in a standard way based on these instructions:


#5

Your woofhomepage.hyperesources folder is not in the wp-content section. You either have to use an absolute url (http://woof-music.com/woofhomepage.hyperesources/woofhomepage_hype_generated_script.js) or place resources folder in wp-content.