我正在尝试了解有关创建 WordPress 插件的更多信息,请耐心等待,我也在使用 codex 寻求帮助。目前我有一个小插件,它只是从 cdn 加载一个 javascript 文件,然后应该输出一些工具提示。 它似乎没有加载脚本,下面是我的函数的代码,我用它从他们的 cdn 加载谷歌字体没问题,但是是否有不同的代码用于此或者它是否正确?
<?php
/**
* Plugin Name: FFXIV Tooltips
* Plugin URI:
* Description: Tooltips from the FFXIV Lodestone
* Version: 1.0.0
* Author:
* Author URI:
* License:
*/
/* Security - Block Direct Access */
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/* LOAD TOOLTIPS JS FROM XIV
================================================================================ ========= */
function tooltips_xivdb() {
// For Primary Header
wp_register_style('tooltips_xivdb','http://xivdb.com/tooltips.js?v=1.6');
wp_enqueue_style( 'tooltips_xivdb');
}
add_action('wp_enqueue_scripts', 'tooltips_xivdb');
/* ================================================================================ ====== */
/* ADDING THE ADMIN MENU
/* ================================================================================ ====== */
/** Step 2 (from text above). */
add_action( 'admin_menu', 'tooltip_menu' );
/** Step 1. */
function tooltip_menu() {
add_menu_page( 'My Plugin Options', 'FFXIV Tools', 'manage_options', 'my- unique-identifier', 'tooltip_options' );
}
/** Step 3. */
function tooltip_options() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
echo '<div class="wrap">';
echo '<h2>tooltips_xivdb</h2>';
echo '<p>Add Shortcode for Items Tooltips from FFXIV Lodestone</p>';
echo '<p>field to display code</p>';
}
?>
最佳答案
当它是一个脚本时,您正在使用 wp_enqueue_style()
。这可能会混淆系统并因此忽略它的执行。
你应该使用 wp_enqueue_script
此外,为了便于阅读,我总是尽量使函数名称和脚本名称不同。
试试这个
function tooltips_xivdb_scripts() {
// For Primary Header
wp_enqueue_script('tooltips_xivdb','http://xivdb.com/tooltips.js', array(), '1.6', false);
}
add_action('wp_enqueue_scripts', 'tooltips_xivdb_scripts');
关于javascript - 创建 Wordpress 插件并加载外部脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32503438/