dongting7352 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 Wordpress.org 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.

    <?php
    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');

    if(!empty($pp_advance_enable_responsive))
    {
        wp_enqueue_style("grid_css", get_stylesheet_directory_uri()."/css/grid.css", false, $pp_theme_version, "all");
    }

    if(isset($_SESSION['pp_slider_style']))
    {
        $pp_slider_style = $_SESSION['pp_slider_style'];
    }
    else
    {
        $pp_slider_style = get_option('pp_slider_style');
    }

    if($pp_slider_style=='full')
    {
        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="http://maps.google.com/maps/api/js?sensor=false"></script>

<?php   
    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.
     */
    wp_head();
?> 
  • 写回答

2条回答 默认 最新

  • 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', 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js', 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
    

    MORE INFO

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)