我正在尝试在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' );
答案 0 :(得分:1)
你需要像这样使用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/