Last active
December 15, 2015 15:09
-
-
Save robneu/5280112 to your computer and use it in GitHub Desktop.
Register a general javascript file using the EXAMPLE_JS_URL constant defined in the main plugin file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Enqueue a JavaScript file using a constant | |
* called EXAMPLE_JS_URL to get the plugin's js directory url. | |
* | |
* @author FAT Media <http://youneedfat.com> | |
* @copyright Copyright (c) 2013, FAT Media, LLC | |
* @license GPL-2.0+ | |
*/ | |
/** | |
* Enqueue with hook 'wp_enqueue_scripts', | |
* which can be used for front end CSS and JavaScript | |
*/ | |
add_action( 'wp_enqueue_scripts', 'example_load_javascript' ); | |
/** | |
* Enqueue plugin js-file | |
*/ | |
function example_load_javascript() { | |
// Add a trailing slash to the js url | |
$js_url = trailingslashit( EXAMPLE_JS_URL ); | |
// Enqueue general.js file which depends on jQuery | |
wp_enqueue_script( 'example-general', $js_url . 'general.js' , array( 'jquery' ), '1.0', true ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A full tutorial on defining and using plugin URLs in a WordPress Must Use plugin can be found at http://youneedfat.com/get-the-mu-plugin-directory-url/