Creating a WordPress Plugin and loading external scripts

Im trying to learn more about creating WordPress plugins so bear with me please, i am also using the codex for help. At the moment i have a small plugin that simply loads a javascript file from a cdn and then should output some tooltips.
It doesnt seem to be loading the script though, the code for my function below, i used it to load google fonts from their cdn no problem, but is there a different code to use for this or is it correct?

<?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>';
}

?>

Related posts

2 comments

  1. You’re using wp_enqueue_style() when its a script. This can be confusing the system and therefore omitting it from executing.

    You should be using wp_enqueue_script

    Also, I always try to make the function names and script names different for easy reading.

    Try this

    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');
    
  2. You shouldn’t be using wp_enqueue_style() if you’re trying to include a script. Rather, you should be using wp_enqueue_script():

    function tooltips_xivdb() {
        wp_enqueue_script( 'tooltips_xivdb', 'http://xivdb.com/tooltips.js?v=1.6' );
    }
    add_action('wp_enqueue_scripts', 'tooltips_xivdb');
    

Comments are closed.