【发布时间】:2013-08-21 13:08:58
【问题描述】:
我已经在functions.php 中成功地将 jQuery 链接到 WordPress。但是,center.js 似乎没有加载。我这么说是因为控制台给了我这个错误:Uncaught TypeError: Object [object Object] has no method 'center'
我在header.php 中调用所有带有<?php wp_head(); ?> 的脚本。这是我的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' );
?>
有人能帮忙解决这个问题吗?
【问题讨论】:
-
可以粘贴一下trans.js的内容吗?这是你的“中心”方法被调用的地方吗?
-
Wordpress 在 wp-includes\js\jquery 中带有自己的 jQuery,为什么要针对旧版本进行更改?它可能会破坏其他插件或主题。
标签: php jquery wordpress plugins