Created
August 24, 2011 17:17
-
-
Save jasonrhodes/1168588 to your computer and use it in GitHub Desktop.
A simple plugin to properly include css and javascript files into a WordPress site. * -(these files won't be minified and concatenated unless you use WP Total Cache or something similar.)
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 | |
/** | |
* @package MyPlugin | |
* @version 1.0 | |
* | |
* Plugin Name: MyPlugin | |
* Plugin URI: http://myurl.com/myplugin | |
* Description: A simple plugin to properly include css and javascript files into a WordPress site. | |
* -(these files won't be minified and concatenated unless you use WP Total Cache or something similar.) | |
* Author: Jason Rhodes | |
* Version: 1.0 | |
* Author URI: http://jasonthings.com | |
*/ | |
// Note: Always prefix your plugin function names, constants, etc. | |
// For more on why, see Nacin's article: http://wp.me/pQEdq-2B | |
define('PREFIX_MYPLUGIN_VERSION', '1.0.0'); | |
define('PREFIX_MYPLUGIN_PLUGIN_URL', plugin_dir_url( __FILE__ )); | |
function prefix_myplugin_init() { | |
/* First, learn about how to register scripts and styles, | |
* how to register dependencies, the difference between the handle | |
* and the filename, etc. | |
* http://codex.wordpress.org/Function_Reference/wp_register_script | |
* http://codex.wordpress.org/Function_Reference/wp_register_style | |
*/ | |
// If you have CSS to include, drop the css files into your plugin directory and queue them like so: | |
wp_register_style('prefix_myplugin.css', PREFIX_MYPLUGIN_PLUGIN_URL . 'myplugin.css'); | |
wp_enqueue_style('prefix_myplugin.css'); | |
// For JavaScript files, drop the .js files into your plugin directory and queue them here: | |
wp_register_script('prefix_myplugin.js', PREFIX_MYPLUGIN_PLUGIN_URL . 'myplugin.js', array('jquery'), "1.0.0", true); | |
wp_enqueue_script('prefix_myplugin.js'); | |
} | |
add_action('init', 'prefix_myplugin_init'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment