Skip to content

Instantly share code, notes, and snippets.

@twright
Created September 25, 2012 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twright/3779749 to your computer and use it in GitHub Desktop.
Save twright/3779749 to your computer and use it in GitHub Desktop.
Basic outline of a wordpress plugin
<?php
class ExampleWordpressPlugin {
const PLUGIN_NAME = 'example-plugin';
const PLUGIN_VERSION = '0.01';
/**
* The constructor of the class.
*/
public function __construct() {
$this->hooks();
}
/**
* Include the required scripts / styles for the plugin.
*/
public function scripts_and_styles() {
// Include the CSS
wp_enqueue_style( self::PLUGIN_NAME . '-style',
plugins_url( 'css/style.css', __FILE__ ), array(),
self::PLUGIN_VERSION, 'all' );
// Include the JavaScript
wp_enqueue_script( self::PLUGIN_NAME . '-script',
plugins_url( 'js/script.js' ), array( 'jquery' ),
self::PLUGIN_VERSION, true );
}
/**
* Register hooks with WordPress to call the desired functions when
* required.
*/
public function hooks() {
add_action( 'wp_enqueue_scripts',
array( $this, 'scripts_and_styles' ) );
}
}
new ExampleWordpressPlugin();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment