我在我的插件中使用 animate.css 流行的动画库。 如何知道其他插件或主题已在页面中存在相同的 animate.css 库。 我知道 CSS 标识符始终保持唯一,例如
my-plugin-animate-css
那么如何查找是否存在相同的css或js文件呢?
add_action('wp_enqueue_scripts', 'check_font_animate', 99999);
function check_font_animate() {
global $wp_styles;
$srcs = array_map('basename', (array) wp_list_pluck($wp_styles->registered, 'src') );
if ( in_array('animate.css', $srcs) || in_array('animate.min.css', $srcs) ) {
/* echo 'animate.css registered'; */
} else {
wp_enqueue_style('animate', get_template_directory_uri() . '/animate.css' );
}
}
请尝试上面的代码吗?我觉得对你有帮助。