0

I have this js function (the textualizer.js is external) but I can't make it works on WordPress. Any help?

I already added

wp_register_script( 'textualizer', WP_THEME_URL . '/assets/js/textualizer.js');
wp_enqueue_script( 'textualizer' );

to theme functions.

What am I doing wrong? I know it's probably simple, but I can't figure it out.

EDIT: i changed the function in functions.php, a user in irc channel told me that i was missing the correct action hook. still doesn't work... http://pastebin.com/L8ZRSvzU

3
  • 1
    Where are you calling this code? Does a script link get output in the rendered source? (Side note: use **get_template_directory_uri() ** rather than WP_THEME_URL.) Mar 4, 2013 at 18:13
  • You can see it in the pastebin in EDIT. I put the function in functions.php, then i use it in a template page. the console in the developer tool give me the error: Uncaught TypeError: Object function (j,s){return new b.fn.init(j,s)} has no method 'Deferred' and it links me to the plugin file, that should work. Mar 5, 2013 at 16:02
  • Close-voted as too localized. Your problem is that you're deregistering core jQuery and registering an older version. Mar 5, 2013 at 16:45

4 Answers 4

2

Using Google with the error message you posted in your comment, Google show me this: The Deferred object, introduced in jQuery 1.5

Your source code says, that you use jQuery 1.4.4.

jQuery is bundled with WordPress and it's version is 1.8.3. Please use the bundled jQuery and not one from an CDN.

2
  • Yep; this is the problem: <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js?ver=3.5.1'></script>. Where do you deregister core jQuery and register jQuery 1.4.4? Wherever it is, get rid of it. Mar 5, 2013 at 16:44
  • Thanks again. yeah, i figured out, but I'm using the jQuery bundled with WP. I use the lib with '<?php wp_enqueue_script('jquery'); ?>' in the header, and in my template i just use get_header. So, where the plugin is using jQuery 1.4.4. ? some way to know? ( firebug? ) I'm still new to this. Mar 5, 2013 at 16:44
2

textualizer() is a jQuery plugin, so you should set a dependency to jQuery

wp_register_script(
  'textualizer',
  get_template_directory_uri() . '/assets/js/textualizer.js',
  array( 'jquery' ),
  false, // no version
  true // load into footer
);

Even if you load jQuery first, the dependency make sure the jQuery plugin is loaded after jQuery.

And it is always a good idea to use a console like Firebug in FireFox or the build in developer tools in Chrome. The console list javascript errors which are very important informations.

1
1

Not quite sure where WP_THEME_URL links to, but here is an idea. Depending on whether you're calling the file of a child or parent theme, you must use the accurate path.

For Example, if you want to refference the parent directory use get_template_directory_uri() which is always going to look inside the parent directory.

Or if you want to specify that the file is in the child theme use get_stylesheet_directory_uri(), which is gonna fallback to the parent if the child file does not exsist.

Just replace WP_THEME_URL and see if that helps.

1
  • done it, still doesn't work. thanks anyway Mar 5, 2013 at 16:02
0

Everythings works fine. The problem was the library too old. Thanks to everyone!

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