wordpress后台样式
Many WordPress plugins implicitly inject stylesheets and JavaScript files into the page on each page load. If you don't plan on custom-styling for elements created by the plugin, that's no problem...but you can get caught in a CSS specificity battle if you do intend custom styling. If the plugin is created properly (which is sometimes a big "if" when it comes to WordPress plugins), you can programmatically tell these files not to load from within your given theme.
许多WordPress插件会在每次加载页面时隐式将样式表和JavaScript文件注入页面。 如果您不打算为插件创建的元素进行自定义样式,那没问题...但是,如果您打算自定义样式,则可能会陷入CSS特殊性之争。 如果插件创建正确(当涉及到WordPress插件时,有时会是一个很大的“ if”),则可以以编程方式告诉这些文件不要从给定的主题中加载。
When scripts and styles are added properly, they use the wp_enqueue_style
and wp_enqueue_script
functions within the plugin files as such:
正确添加脚本和样式后,它们将在插件文件中使用the wp_enqueue_style
和wp_enqueue_script
函数,例如:
// Styles Format: wp_enqueue_style($handle, $src, $deps, $ver, $media);wp_register_style('pagination-style', plugins_url('style.css', __FILE__));wp_enqueue_style('pagination-style');// Script Format: wp_enqueue_script($handle, $src, $deps, $ver, $in_footer);wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js');wp_enqueue_script('jquery');
Those handle names are incredibly important, as within your theme's functions.php
you'll be adding their counterpart calls of wp_dequeue_style
and wp_dequeue_script
functions:
这些句柄名称非常重要,因为在主题的functions.php
您将添加它们的对等调用wp_dequeue_style
和wp_dequeue_script
函数:
// Get out of my page!wp_dequeue_style('pagination-style');wp_dequeue_script('jquery');
In the past I've argued that each plugin should make including their styles and scripts optional, but with these simple functions, I'm not as frustrated as I once was. You'll need to dig into the plugin code to find their script and style handles, but it will be will worth it in the end!
在过去,我认为每个插件都应使其样式和脚本(包括脚本)为可选项,但是有了这些简单的功能,我就不会像以前那样沮丧。 您需要深入研究插件代码以找到其脚本和样式句柄,但最终还是值得的!
翻译自:
wordpress后台样式