如何在 wordpress 上包含外部 code/library javascript?

How to include external code/library javascript on wordpress?

我想在 wordpress 上使用外部 JS 库,我应该如何将它添加到我的 wordpress 库中。库是 viewerjs.

使用排队样式代码

<?php
function add_theme_codes() {
   wp_enqueue_style( ‘style’, ‘your external file url goes here’, ‘all’);
}
add_action( ‘wp_enqueue_scripts’, ‘add_theme_codes’ );
?>

确保您已将 wp_head 标签包含在 head 标签中

摘自文档:

https://developer.wordpress.org/themes/basics/including-css-javascript/

Enqueue the script or style using wp_enqueue_script() or wp_enqueue_style()

示例:

wp_enqueue_script( 'script', get_template_directory_uri() . '/js/script.js', array ( 'jquery' ), 1.1, true);