【问题标题】:Insert Gridster into WordPress Backend将 Gridster 插入 WordPress 后端
【发布时间】:2016-01-04 20:24:44
【问题描述】:

我一直在尝试将 Gridster 包含到我的 WordPress 后端中,但它根本不起作用。前端工作正常,但我不知道为什么,因为文件实际上位于以下目录中。

我尝试的第一种方法:

function add_my_scripts() {
  wp_enqueue_script('jquery');
  wp_enqueue_script( "gridster-script", plugins_url( '/js/jquery.gridster.min.js', __FILE__  ), array('jquery') );
  wp_enqueue_script( "gridster-script-extra", plugins_url( '/js/jquery.gridster.with-extras.min.js', __FILE__ ), array('gridster-script'), true );
  wp_enqueue_script( "gridster-script-custom",  plugins_url( '/js/gridster.js', __FILE__ ), array('jquery'), '1.0', true );
 }

第二个:

function add_my_scripts() {
  wp_enqueue_script('jquery');
  wp_enqueue_script('gridster-script', plugin_dir_url(__FILE__) . '/js/jquery.gridster.min.js', array('jquery') );
  wp_enqueue_script('gridster-script-extra', plugin_dir_url(__FILE__) . '/js/jquery.gridster.with-extras.min.js', array('gridster-script') );
  wp_enqueue_script('gridster-script-custom', plugin_dir_url(__FILE__) . '/js/gridster.js', array('jquery') );
 }

第三个也是最后一个:

function add_my_scripts() {
  wp_enqueue_script('jquery');
  wp_enqueue_script( 'gridster-script', get_template_directory_uri() . '/js/jquery.gridster.min.js', array('jquery'), '1.0.0', true );
  wp_enqueue_script( 'gridster-script-extra', get_template_directory_uri() . '/js/jquery.gridster.with-extras.min.js', array('gridster-script'), '1.0.0', true );
  wp_enqueue_script( 'gridster-script-custom', get_template_directory_uri() . '/js/gridster.js', array('jquery'), '1.0.0', true );
 }

【问题讨论】:

    标签: php jquery wordpress gridster


    【解决方案1】:

    您不能随意使用插件 url 功能,需要根据您的用例选择正确的功能。假设__FILE__ 正确引用了主插件文件,您需要将该函数挂钩到admin_enqueue_scripts 操作挂钩中:

    function add_my_scripts() {
        wp_enqueue_script( "gridster-script", plugins_url( 'js/jquery.gridster.min.js', __FILE__  ), array('jquery') );
        wp_enqueue_script( "gridster-script-extra", plugins_url( 'js/jquery.gridster.with-extras.min.js', __FILE__ ), array('gridster-script'), true );
        wp_enqueue_script( "gridster-script-custom",  plugins_url( 'js/gridster.js', __FILE__ ), array('jquery'), '1.0', true );
    }
    add_action( 'admin_enqueue_scripts', 'add_my_scripts' );
    

    【讨论】:

    • 谢谢,我不知道。这篇文章也对我有帮助,因为该文件已包含在内但正在捕获错误。 (stackoverflow.com/questions/12343714/…)
    • 不客气。如果这回答了问题,请将其选为“正确”。
    • 抱歉忘记了:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多