1

I've successfully linked jQuery to WordPress within the functions.php. However, it appears that the center.js is not loading. I say this, because the console is giving me this error: Uncaught TypeError: Object [object Object] has no method 'center'

I am calling all scripts with <?php wp_head(); ?> within the header.php. Here is my functions.php:

<?php

function add_google_jquery() {
   if ( !is_admin() ) {
      wp_deregister_script('jquery');
      wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"), false);
      wp_enqueue_script('jquery');
   }
}
add_action('wp_print_scripts ', 'add_google_jquery');

// just added jQuery

function add_google_center() {
   if ( !is_admin() ) {
      wp_register_script('center', ("http://jquerydevbrazil.googlecode.com/svn/trunk/jquery.center.js"), false);
      wp_enqueue_script('center');
   }
}
add_action('wp_print_scripts_center ', 'add_google_center');


set_post_thumbnail_size( 800, 600, 1 );

function PA_stylesheet() {
    wp_enqueue_style( 'pa-style', get_stylesheet_uri() );

}

add_action( 'wp_enqueue_scripts', 'PA_stylesheet' );

function PA_javascript() {
    wp_enqueue_script( 'custom-script',
        get_stylesheet_directory_uri() . '/tran.js',
        array( 'jquery' )
    );
}

add_action( 'wp_enqueue_scripts', 'PA_javascript' );

?>

Would anyone be able to help solve this problem?

2
  • Can you paste the contents of trans.js? Is this where your 'center' method is being called? Commented Aug 19, 2013 at 17:07
  • Wordpress comes with its own jQuery in wp-includes\js\jquery, why change it against an older version? It might break other plugins or themes. Commented Oct 11, 2013 at 14:01

1 Answer 1

2

You shouldn't be using wp_print_scripts. Use wp_enqueue_scripts instead.

http://codex.wordpress.org/Plugin_API/Action_Reference/wp_print_scripts

(this is for tying in your add_google_jquery and add_google_center functions)

So, all you need to do is replace 'wp_print_scripts' with 'wp_enqueue_scripts' and you should be good to go

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.