Adding a new shortcode requires the following function in your plugin file:
add_shortcode( 'google-cal', 'output_calendar' );
This means that your plugin has a function named output_calendar
that is called anytime WordPress sees the shortcode [google-cal]
in post or page content. Put your existing code in the output_calendar
function.
You only need three things in your plugin:
1) The comment block that identifies your plugin.
/*
Plugin Name: Joel's Google calendar shortcode
Description: Outputs Google calendar content.
Version: 1.0
Author: Joel
Author URI: http://www.monkeycalendar.com/
License: GPL2 (or whatever)
*/
2) The add_shortcode
function call.
3) The output_calendar
function definition.
Put the plugin php file in wp-content/plugins (in its own folder or at the root there) and activate it in the admin UI. Add the shortcode to a post or page and see it appear in your site.
Read up on the shortcode docs to learn how to pass parameters to your shortcode function.
Note that if you just want the content to appear in the template outside of post or page content, either put the output_calendar
function itself in the template files at the location where you want the calendar to appear or use the do_shortcode
function.