如何使用 wordpress 查找已被其他插件或主题排队的相同 css 库

问题描述 投票:0回答:1

我在我的插件中使用 animate.css 流行的动画库。 如何知道其他插件或主题已在页面中存在相同的 animate.css 库。 我知道 CSS 标识符始终保持唯一,例如

my-plugin-animate-css
那么如何查找是否存在相同的css或js文件呢?

php css wordpress wordpress-theming
1个回答
0
投票
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' );
  }
}

请尝试上面的代码吗?我觉得对你有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.