2013-01-20 18:03 阅读 56

如何强制主题使用Wordpress jQuery?

I installed a new awesome theme and got it working after hard work. Everything's running fine, except the 'Add Media', 'Add Link' and the 'HTML Editor'.

I read how to diagnose the problem according the official diagnosing instructions and posted it on forum as they told me to, but I got no response yet and I don't think I'll be getting one anyway.

I used this:

define('SCRIPT_DEBUG', true);

And it did solve the problem for 'Add Media' and 'HTML Editor', but not for the 'add link'. When I click it, it DOES open, but the screen goes grey and the box is way far in the bottom-left corner and and I can't close it with the 'Cancel' button (see here).

I did try disabling all the plugins but it doesn't work (see here).

In summary the problem is that the theme probably has its own version of jQuery and Wordpress 3.5 has its own. How do I force the theme to use Wordpress's jQuery? Or force Wordpress to use the theme's jQuery? Anything that will fix the editor, I want that.

EDIT: Just to make it clearer. There is NO conflict with plugins. The conflict is between Wordpress's jQuery and the theme's jQuery.

If it helps, this is in the header file.

    wp_enqueue_style("jqueryui_css", get_stylesheet_directory_uri()."/css/jqueryui/custom.css", false, $pp_theme_version, "all");
    wp_enqueue_style("screen_css", get_stylesheet_directory_uri()."/css/screen.css", false, $pp_theme_version, "all");
    wp_enqueue_style("tipsy_css", get_stylesheet_directory_uri()."/css/tipsy.css", false, $pp_theme_version, "all");
    wp_enqueue_style("fancybox_css", get_stylesheet_directory_uri()."/js/fancybox/jquery.fancybox.css", false, $pp_theme_version, "all");
    wp_enqueue_style("flexslider_css", get_stylesheet_directory_uri()."/js/flexslider/flexslider.css", false, $pp_theme_version, "all");

    $pp_advance_enable_responsive = get_option('pp_advance_enable_responsive');

        wp_enqueue_style("grid_css", get_stylesheet_directory_uri()."/css/grid.css", false, $pp_theme_version, "all");

        $pp_slider_style = $_SESSION['pp_slider_style'];
        $pp_slider_style = get_option('pp_slider_style');

        wp_enqueue_style("pp_slider_style", get_stylesheet_directory_uri()."/css/fullslide.css", false, $pp_theme_version, "all");
    wp_enqueue_style("colorpicker.css", get_stylesheet_directory_uri()."/js/colorpicker/css/colorpicker.css", false, $pp_theme_version, "all");

<script type="text/javascript" src=""></script>

    wp_enqueue_script("jquery", get_stylesheet_directory_uri()."/js/jquery.js", false, $pp_theme_version);
    wp_enqueue_script("jQuery_UI_js", get_stylesheet_directory_uri()."/js/jquery-ui.js", false, $pp_theme_version);
    wp_enqueue_script("swfobject.js", get_stylesheet_directory_uri()."/swfobject/swfobject.js", false, $pp_theme_version);
    wp_enqueue_script("colorpicker.js", get_stylesheet_directory_uri()."/js/colorpicker.js", false, $pp_theme_version);
    wp_enqueue_script("eye.js", get_stylesheet_directory_uri()."/js/eye.js", false, $pp_theme_version);
    wp_enqueue_script("utils.js", get_stylesheet_directory_uri()."/js/utils.js", false, $pp_theme_version);
    wp_enqueue_script("fancybox_js", get_stylesheet_directory_uri()."/js/fancybox/jquery.fancybox.pack.js", false, $pp_theme_version);
    wp_enqueue_script("jQuery_easing", get_stylesheet_directory_uri()."/js/jquery.easing.js", false, $pp_theme_version);
    wp_enqueue_script("jQuery_hint", get_stylesheet_directory_uri()."/js/hint.js", false, $pp_theme_version);
    wp_enqueue_script("jQuery_validate", get_stylesheet_directory_uri()."/js/jquery.validate.js", false, $pp_theme_version);
    wp_enqueue_script("jQuery_tipsy", get_stylesheet_directory_uri()."/js/jquery.tipsy.js", false, $pp_theme_version);
    wp_enqueue_script("reflection_js", get_stylesheet_directory_uri()."/js/reflection.js", false, $pp_theme_version);
    wp_enqueue_script("browser_js", get_stylesheet_directory_uri()."/js/browser.js", false, $pp_theme_version);
    wp_enqueue_script("flexslider_js", get_stylesheet_directory_uri()."/js/flexslider/jquery.flexslider-min.js", false, $pp_theme_version);
    wp_enqueue_script("marquee_js", get_stylesheet_directory_uri()."/js/jquery.marquee.js", false, $pp_theme_version);
    wp_enqueue_script("jwplayer_js", get_stylesheet_directory_uri()."/js/jwplayer.js", false, $pp_theme_version);
    wp_enqueue_script("gmap_js", get_stylesheet_directory_uri()."/js/gmap.js", false, $pp_theme_version);
    wp_enqueue_script("custom_js", get_stylesheet_directory_uri()."/js/custom.js", false, $pp_theme_version);

    /* Always have wp_head() just before the closing </head>
     * tag of your theme, or you will break many plugins, which
     * generally use this hook to add elements to <head> such
     * as styles, scripts, and meta tags.
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    dongxili9934 dongxili9934 2013-01-20 19:01
    // only for Themes since WordPress 3.0
    function jquery_190() {
        if ( !is_admin() ) { // actually not necessary, because the Hook only get used in the Theme
            wp_deregister_script( 'jquery' ); // unregistered key jQuery
            wp_register_script( 'jquery', '', false, '1.9.0'); // register key jQuery with URL of Google CDN
            wp_enqueue_script( 'jquery' ); // include jQuery
    add_action( 'after_setup_theme', 'jquery_190' ); // Theme active, include function


    点赞 评论 复制链接分享
  • dsxcv5652 dsxcv5652 2013-01-20 18:15

    Please see this discussion on wordpress forums that explore the reasons, why this is done as it is and what are available workarounds.

    This is what has worked for me:

    // Include this in functions.php or the theme
    if( !is_admin()){
        wp_register_script('jquery', (""), false, '1.9.0');
    点赞 评论 复制链接分享