如何在Wordpress插件开发中包含bootstrap? [英] How to include bootstrap in Wordpress plugin development?

查看:404
本文介绍了如何在Wordpress插件开发中包含bootstrap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发插件,我想在我的插件中包含bootstrap。包含的最佳方式是什么?我找不到任何与此相关的东西,到目前为止我找到了几个bootstrap插件,我不需要,我需要在我的插件中包含一些来自bootstrap的js和css元素。我是bootstrap的新手。

I am developing the plugin, and I would like to include bootstrap in my plugin. What is the best way to include? I couldn't find anything related to this, so far I have found several bootstrap plugin, which I dont need, I need to include some js and css element from bootstrap in my plugin. I am new to bootstrap.

此外,我尝试了类似于WP主题的内容,但它不起作用?

Also I have tried something similar like including in WP theme, but it doesn't work?

如果你需要更多信息,请问我,我会提供给你

If you need more information, please ask me, I will provide you

我试图在主文件中包含类似于WP主题的内容,index.php:

I have tried to include something similar to WP theme in the main file, index.php this :

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<!-- Latest compiled and minified JavaScript -->
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>                 


推荐答案

您需要使用 wp_register_script ()然后 wp_enqueue_script() for js。

You need to use wp_register_script() and then wp_enqueue_script() for js.

你需要使用 wp_register_style()然后 wp_enqueue_style() for css。

You need to use wp_register_style() and then wp_enqueue_style() for css.

请参阅以下js示例...

See the following js example...

wp_register_script('prefix_bootstrap', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js');
wp_enqueue_script('prefix_bootstrap');

现在为css做同样的事情......

And now do the same for the css...

wp_register_style('prefix_bootstrap', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
wp_enqueue_style('prefix_bootstrap');

将这些放在可重用的方法中是个好主意,以防你使用ajax。这样,您就不需要重新放置ajax方法中的每个脚本或样式表。

It's a good idea to place these in a reusable method in case you will be using ajax. This way, you don't need to relist every script or stylesheet within the ajax methods.

function prefix_enqueue() 
{       
    // JS
    wp_register_script('prefix_bootstrap', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js');
    wp_enqueue_script('prefix_bootstrap');

    // CSS
    wp_register_style('prefix_bootstrap', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
    wp_enqueue_style('prefix_bootstrap');
}

使用prefix_有助于防止冲突并为您省去麻烦从长远来看。

The use of the "prefix_" will help prevent conflicts and save you some trouble in the long run.

这篇关于如何在Wordpress插件开发中包含bootstrap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆