【问题标题】:Loading scripts only for certain admin page仅为某些管理页面加载脚本
【发布时间】:2013-12-11 19:18:08
【问题描述】:

我正在尝试在我当前的项目中为选项树框架添加日期和时间选择器。我正在使用global $pagenow;,但想知道是否有其他方法可以在某些管理页面上加载脚本?

这是我的代码:

global $pagenow;

//Check if current admin page is Option Tree settings
if ( $pagenow == 'themes.php' && $_GET['page'] == 'ot-theme-options' ) {

    // Register and Enqueue Date & Time Picker Scripts
    function orn_admin_register() {

            wp_enqueue_script( 'jquery-date-timepicker', get_template_directory_uri()."/inc/backend/datetimepicker/jquery.datetimepicker.js", array('jquery'),'1.4.2',true);

            wp_enqueue_style('jquery-date-timepicker-style', get_template_directory_uri().'/inc/backend/datetimepicker/jquery.datetimepicker.css', false);
    }

    add_action( 'admin_enqueue_scripts', 'orn_admin_register' ); 

    //Add Inline script to trigger Date & Timepicker
    function admin_inline_js(){
        echo "<script type='text/javascript'>\n";
        echo "jQuery(document).ready(function($) {";
        echo "\n$('#orn_days_underc').datetimepicker()";
        echo "\n})\n</script>";

    }
    add_action( 'admin_print_scripts', 'admin_inline_js', 20 );

}

【问题讨论】:

标签: wordpress


【解决方案1】:

如果有人需要,使用 WordPress 推荐的方法将管理脚本加入队列的最佳方式。

function custom_option_tree_admin_scripts($hook) {

      if   ( 'appearance_page_ot-theme-options' == $hook ) { 

          //Enqueue some scripts or styles here only for Option Tree

      }
}
add_action('admin_enqueue_scripts', 'custom_option_tree_admin_scripts');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多