javascript - 我的插件无法识别 Bootstrap 和 css

标签 javascript css wordpress

我正在尝试在 Wordpress 上制作我自己的插件,但是 Bootstrap 和 css 不起作用,它们之间没有形成连接。这是我的代码,如果您对此有任何想法,我将非常感激。

 function my_options_style() {
      wp_register_style('my_options_css', plugin_dir_url(__FILE__) . 'css/style.css', false, '1.0.0');
      wp_register_style('bootstrap_options_css', plugin_dir_url(__FILE__) . 'includes/bootstrap-3.3.6-dist/css/bootstrap.min.css', false, '1.0.0');
      wp_register_style('bootstrap_css', plugin_dir_url(__FILE__) . 'includes/bootstrap-3.3.6-dist/css/bootstrap-theme.min.css', false, '1.0.0');
      wp_enqueue_style('my_options_css');
      wp_enqueue_style('bootstrap_options_css');
      wp_enqueue_style('bootstrap_css');
     }
     add_action('admin_enqueue_scripts', 'my_options_style');

     function theme_scripts() {
      wp_enqueue_script( 'my-ads', plugin_dir_url(__FILE__) . 'includes/bootstrap-3.3.6-dist/js/bootstrap.min.js', array(), '1.0.1', true );
     }
     add_action( 'wp_enqueue_scripts', 'theme_scripts' );

最佳答案

你需要像这样使用 wp_register_style() & wp_register_script()

注册脚本演示

// Register Script
function custom_scripts() {

    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', '//code.jquery.com/jquery-2.1.1.min.js', false, '2.1.1', false );
    wp_enqueue_script( 'jquery' );

    wp_deregister_script( 'bootstrap' );
    wp_register_script( 'bootstrap', '//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js', array( 'jquery' ), '3.2.0', false );
    wp_enqueue_script( 'bootstrap' );

}
add_action( 'wp_enqueue_scripts', 'custom_scripts' );

对于注册样式

// Register Style
function custom_styles() {

    wp_register_style( 'bootstrap', '//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css', false, '3.2.0' );
    wp_enqueue_style( 'bootstrap' );

    wp_register_style( 'bootstrap-theme', '//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css', array( 'bootstrap' ), '3.2.0' );
    wp_enqueue_style( 'bootstrap-theme' );

}
add_action( 'wp_enqueue_scripts', 'custom_styles' );

了解更多详情

https://developer.wordpress.org/reference/functions/wp_enqueue_style/

https://developer.wordpress.org/reference/functions/wp_enqueue_script/

关于javascript - 我的插件无法识别 Bootstrap 和 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35060492/

相关文章:

php - 如何在谷歌云平台上从 PHP 7.0 升级到 7.3?

php - 在 Wordpress 中制作完整的浏览器窗口响应图像

javascript - 你如何退出 JavaScript 中的调用函数?

javascript - 如何使用javascript获取json元素

javascript - function getLargestElement - 如何让它与充满负数的数组一起工作?

html - 列表项周围的边框,包括列表样式类型

Wordpress 联系表 7 datepicker 更改日期格式

javascript - FlatList 列表项背景颜色

html - 如何在 div 元素中包含标题和滚动部分

jQuery 添加选中的 ="checked"到单选框/复选框