BaseURL和与插件交互的问题

时间:2016-11-26 作者:Craig Tucker

我已经建立了一个插件,它似乎挂在ok。它至少可以运行。然而,它的加载速度非常慢。我已附上我的控制台日志结果。在某些情况下,基本url似乎没有正确构建。www.mydomain。com/wordpress/plugin正在与/wp-includes/js/jquery/相结合。这些条目应为www.mydomain。com/wordpress/wp包括/js/jquery/。我也看到这是不一致的,有时它建造得很好。因此,我试图找到发生这种情况的文件,但我有点迷路了。任何提示都会有帮助。

GET https://www.example.com/wordpress/plugin/wp-includes/js/jquery/jquery.js?ver=1.12.4 (index):54
GET https://www.example.com/wordpress/plugin/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1 404 (Not Found)  (index):55
GET https://www.example.com/wordpress/plugin/wp-includes/js/jquery/ui/core.min.js?ver=1.11.4    (index):603 
GET https://www.example.com/wordpress/plugin/wp-includes/js/jquery/ui/datepicker.min.js?ver=1.11.4 404 (Not Found)  (index):604
GET https://www.example.com/wordpress/plugin/wp-includes/js/jquery/ui/widget.min.js?ver=1.11.4  (index):606
GET https://www.example.com/wordpress/plugin/wp-includes/js/jquery/ui/slider.min.js?ver=1.11.4  (index):608
GET https://www.example.com/wordpress/plugin/wp-includes/js/jquery/ui/mouse.min.js?ver=1.11.4   (index):607
GET https://www.example.com/wordpress/plugin/wp-includes/js/jquery/ui/button.min.js?ver=1.11.4  (index):609
GET https://www.example.com/wordpress/plugin/wp-includes/js/wp-embed.min.js?ver=4.5.3   (index):616
GET https://www.example.com/wordpress/pluginjs/wp-emoji-release.min.js?ver=4.5.3    (index):28
GET https://www.example.com/wordpress/plugin/wp-includes/js/jquery/ui/slider.min.js?ver=1.11.4  (index):608 
GET https://www.example.com/wordpress/plugin/wp-includes/js/jquery/ui/button.min.js?ver=1.11.4 404 (Not Found)  (index):609
GET https://www.example.com/wordpress/plugin/wp-includes/js/wp-embed.min.js?ver=4.5.3 404 (Not Found)   (index):616
Uncaught TypeError: jQuery(...).tinyNav is not a function(…)    TinyNav.js?ver=4.5.3:91
Google sync successful  frontend_book.js:513

2 个回复
SO网友:Craig Tucker

通过将以下内容粘贴到我的函数中,大部分问题都得到了解决。php

     function my_init()   
{  
    if (!is_admin())   
    {  
        wp_deregister_script(\'jquery\');  

        // Load the copy of jQuery that comes with WordPress  
        // The last parameter set to TRUE states that it should be loaded  
        // in the footer.  
        wp_register_script(\'jquery\', \'/wp-includes/js/jquery/jquery.js\', FALSE, \'1.11.4\', TRUE);  

        wp_enqueue_script(\'jquery\');  
    }  
}  
add_action(\'init\', \'my_init\'); 

SO网友:Benoti

如何将这些文件排队/注册?您是否尝试将它们像您的文件一样排队,或将它们视为依赖项?

要使用WordPress核心注册脚本库中的任何文件,只需注册它们并设置插件所需的依赖项wp_register_script (使用wp\\u enqueue\\u scripts操作触发)。

您将找到所有核心注册脚本的列表here

如果已使用wp\\u register\\u script()预先注册的脚本被列为另一个已排队脚本的依赖项,则无需使用wp\\u enqueue\\u script()手动排队。WordPress将自动包括已注册脚本,然后再包括将已注册脚本的句柄列为依赖项的排队脚本。

相关推荐