Last active
December 15, 2015 15:09
-
-
Save robneu/5279916 to your computer and use it in GitHub Desktop.
This code will help you get the URLs for a plugin inside WordPress Must Use directory. This makes it easy for you to use them throughout your plugin in order to reference things like CSS and JavaScript files.
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 | |
/** | |
* Define URLs for a Must Use Plugin | |
* Remember to change EXAMPLE to your plugin prefix | |
* | |
* @author FAT Media <http://youneedfat.com> | |
* @copyright Copyright (c) 2013, FAT Media | |
* @license GPL-2.0+ | |
*/ | |
add_action('init', 'example_plugin_urls'); | |
/** | |
* Hook your URLs to init to to ensure that the "plugins_url" | |
* filters are already hooked at the time the function is called. | |
*/ | |
function example_plugin_urls() { | |
// Define the Main Plugin URL (Replace 'example-plugin' with your plugin folder) | |
define( 'EXAMPLE_PLUGIN_URL', plugins_url( 'example-plugin' , dirname( __FILE__ ) ) ); | |
// Define the Lib URL (Could also be includes, classes etc.) | |
define( 'EXAMPLE_LIB_URL', EXAMPLE_PLUGIN_URL . '/lib' ); | |
// Define URLs Inside the Lib Directory | |
define( 'EXAMPLE_CSS_URL', EXAMPLE_LIB_URL . '/css' ); | |
define( 'EXAMPLE_IMG_URL', EXAMPLE_LIB_URL . '/css/images' ); | |
define( 'EXAMPLE_JS_URL', EXAMPLE_LIB_URL . '/js' ); | |
} |
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/