如何包括CSS和jQuery在我的wordpress插件? [英] How To Include CSS and jQuery in my wordpress plugin?

查看:247
本文介绍了如何包括CSS和jQuery在我的wordpress插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我的wordpress插件中包含CSS和jQuery?

解决方案

对于样式

wp_register_style('namespace',' http://locationofcss.com/mycss.css');



然后使用:
wp_enqueue_style('namespace');
无论你想要加载css。



脚本与上面的一样,但是加载jquery的更快的方法只是使用enqueue加载到你想加载它的页面的init:
wp_enqueue_script('jquery');



除非当然你想使用google库jquery。 >

您还可以有条件地加载脚本依赖的jquery库:
wp_enqueue_script('namespaceformyscript',' http://locationofscript.com/myscript.js ',array('jquery'));


How To Include CSS and jQuery in my wordpress plugin ?

解决方案

For styles wp_register_style( 'namespace', 'http://locationofcss.com/mycss.css' );

Then use: wp_enqueue_style('namespace'); wherever you want the css to load.

Scripts are as above but the quicker way for loading jquery is just to use enqueue loaded in an init for the page you want it to load on: wp_enqueue_script('jquery');

Unless of course you want to use the google repository for jquery.

You can also conditionally load the jquery library that your script is dependent on: wp_enqueue_script('namespaceformyscript', 'http://locationofscript.com/myscript.js', array('jquery'));

这篇关于如何包括CSS和jQuery在我的wordpress插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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