在我的插件中无法识别引导和 css

Bootstrap and css are not being recognized in my plugin

本文关键字:css 识别 我的 插件      更新时间:2023-09-26

我正在尝试在Wordpress上制作自己的插件,但是引导程序和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/