1

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

?>

2 Answers 2

4

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');
Sign up to request clarification or add additional context in comments.

3 Comments

Just a note...The function name and the name of the script don't have anything to do with each other, and shouldn't conflict if they're the same.
True, dumb moment. I still prefer to do it for easy reading anyway.
that fixed it, facepalm its been way to long a day i think if im making mistakes like this. Thanks appreciate the quick and accurate response.
3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.