将自定义CSS添加到短代码中

时间:2015-01-30 03:04:17

标签: wordpress

我正在开发一个wordpress插件。这个插件将使用短代码来显示使用Bootstrap 3设置样式的大块HTML。但是,我不能依赖于主题是否启用了bootstrap 3。从我的插件中有没有办法确保将bootstrap 3库添加到页面中?

我查看了文档,看起来似乎不够清楚。我有一种感觉它与wp_enqueue_script有关,但不确定我需要用来绑定主页/帖子页面/主题标题上的CSS / JS等等。 / p>

1 个答案:

答案 0 :(得分:1)

摘要是,当你的插件加载时,你应该注册bootstrap:

add_action( 'wp_enqueue_scripts', 'my_plugin_register_scripts' );
function my_plugin_register_scripts(){
     wp_register_script('bootstrap','//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js',array('jquery'),'3.3.2',true);
     wp_register_style('bootstrap','//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css', array(), '3.3.2');
}

然后,当您调用短代码时,您将引导程序排入队列:

wp_enqueue_script('bootstrap');
wp_enqueue_style('bootstrap');
相关问题