Minimal Wordpress Shortcode plugin example
Also see: Minimal WordPress JS plugin example Minimal WordPress CSS plugin example
This plugin creates a simple (static - no parameters) shortcode in Wordpress
First, create a directory for your plugin in wp-content/plugins/
, e.g. wp-content/plugins/my-shortcode-plugin
Save the following code as functions.php
in the plugin folder, e.g. wp-content/plugins/my-shortcode-plugin/functions.php
<?php
/*
Plugin Name: My shortcode plugin
*/
function my_shortcode( $atts , $content = null ) {
return '<h2>Shortcode works</h2>';
}
add_shortcode( 'my-shortcode', 'my_shortcode' );
Now activate your plugin your Wordpress admin area.
You can now create a post or pagecontaining this code:
[my-shortcode][/my-shortcode]
which will be rendered like this:
Shortcode works
---------------