Link to home
Start Free TrialLog in
Avatar of MHenry
MHenry

asked on

Need to get jQuery working in head of Wordpress site (colorbox jQuery plugin)

I can't get a jQuery script to work in Wordpress. It worked fine before moving to Wordpress so I know it was working. Here's what I have. Can anyone point out what I'm doing wrong?

In function.php I have added:

	function my_init() {
	if (!is_admin()) {
		wp_deregister_script('jquery');
		wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js', false, '1.3.2', true);
		wp_enqueue_script('jquery');		
		wp_register_style('colorbox_css', get_bloginfo('template_directory') . '/inc/stylesheets/colorbox.css');
		wp_enqueue_style('colorbox_css');
		wp_register_script('colorbox', get_bloginfo('template_directory') . '/inc/scripts/jquery.colorbox-min.js');
		wp_enqueue_script('colorbox');
	}
}
add_action('init', 'my_init');

Open in new window


In the head portion I have this:
<?php wp_head(); ?>
<script type="text/javascript">

			// Dialog			
		jQuery(document).ready(function() {
    	jQuery("#dialog").dialog({
      	bgiframe: true, autoOpen: false, height: 300, width: 450, modal: true
    });
  });

		</script>

Open in new window


And in the <body>, I have this:

<li><a href="#" onclick="jQuery('#dialog').dialog('open'); return false">MyLink</a></li> <span class="barFont">|</span

Open in new window

Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Why are you trying to back to an old version of jQuery?  You might simply be breaking some of the jQuery code that already exists in Wordpress.  This is the current version of the 1.x series: <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
What Dave said:  can you run the script under modern JQuery or will it only work with 1.3.2?

If 1.3.2 is the only option, make sure no other versions of JQuery are loading via a plugin or by the theme. Deregistering JQuery would handle the theme, but a plugin may override it or add to it.
Avatar of MHenry
MHenry

ASKER

ok, I updated the link to jQuery, there are no plugins active.

Still not working.
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MHenry

ASKER

GaryC123,

Yeah, I noticed that right after I first posted. I tried adding those references but it's still not working.

I'm thinking something is wrong in the way I'm adding to the functions.php but I can't figure out what I'm doing wrong.
Would be a lot easier if you posted the link else the rendered HTML.
Avatar of MHenry

ASKER

so the main thing was not linking to the JQuery UI. That and leaving an S off of dialog.

sheesh.

Thanks!