简体   繁体   English

wordpress主题开发中如何使用LESS css?

[英]How to use LESS css in wordpress theme development?

I googled the same question but couldn't find the perfect answer, Can anybody make it clear on how to use LESS CSS in WordPress theme development?我用谷歌搜索了同样的问题,但找不到完美的答案,有人能说清楚如何在 WordPress 主题开发中使用 LESS CSS 吗? I don't want to rely upon online scripts.我不想依赖在线脚本。

I already tried https://github.com/sanchothefat/wp-less but no luck..我已经尝试过https://github.com/sanchothefat/wp-less但没有运气..

Your question is very broad? 您的问题很广泛? Too broad I think. 我认为范围太广。

How does your develop process looks now? 您的开发过程现在看起来如何? How do you want to compile your Less code. 您想如何编译Less代码。

Notice that Less code should be compiled into static CSS. 请注意,应将更少的代码编译为静态CSS。 Of course you can use the in browser version too, but in-browser compiling is not suitable for production. 当然您也可以使用in浏览器版本 ,但是浏览器内编译不适合生产。

Basically you should compile your Less into CSS first. 基本上,您应该先将Less编译为CSS。 You can compile styles.less into styles.css and upload that file into your wp-content/themes/yourthemes folder. 您可以将styles.less编译为styles.css,然后将该文件上传到wp-content/themes/yourthemes文件夹中。 Instead of styles.css you can use any other file and integrate in with the wp_enqueue_style function into your theme. 除了styles.css之外,您还可以使用任何其他文件并将其与wp_enqueue_style函数集成到您的主题中。

In the case that you want your Less code via the WordPress dashboard, you can install the WP Less to CSS plugin. 如果您希望通过WordPress仪表板获取Less代码,则可以将WP Less Less安装到CSS插件。 This plugin compiles your Less code into a static CSS file as described above. 该插件如上所述将您的Less代码编译为静态CSS文件。

The JBST theme use the Less plugin describe above. JBST主题使用上面描述的Less插件。 You can also take a look at the Roots.io theme, which uses Less, npm and grunt to build. 您还可以查看Roots.io主题,该主题使用Less,npm和grunt进行构建。

A process that, for now, I use occasionally.目前,我偶尔使用的过程。 I installed Koala, which creates CSS files from LESS on the fly.我安装了 Koala,它从LESS动态创建了 CSS 个文件。 Then we create style.less and as we write code in it - through, for example, WinSCP upload to the server in the theme folder.然后我们创建style.less并在其中编写代码 - 例如,通过 WinSCP 上传到主题文件夹中的服务器。

You can also use a copy of the site on a local server like OpenServer (OSpanel).您还可以使用本地服务器(如OpenServer (OSpanel))上的站点副本。 With Koala create CSS automatically from LESS in theme folder on local server.使用 Koala 从本地服务器主题文件夹中的 LESS 自动创建 CSS。 After changes - upload them to the work server.更改后 - 将它们上传到工作服务器。

You can use Grunt.js to compile the file locally or some app lice CodeKit. 您可以使用Grunt.js在本地或某些应用程序虱子CodeKit上编译文件。 Also you can use some wordpress plugins like this one: https://wordpress.org/plugins/wp-less/ 您也可以使用一些像这样的wordpress插件: https : //wordpress.org/plugins/wp-less/

I used that plugins before an it works fine. 我在功能正常之前使用了这些插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM