I'm new to Wordpress. I have a website that I coded myself. One of the pages has PHP functions that take a google calendar feed (with hard-coded login info) and displays it as needed.

I am now building a new site on wordpress where I want to use the same code. My reading says I should handle this as creating a new plugin so that I don't overwrite it with any theme updates.

My question: how can I simply copy my PHP code into a file in it's own plugin folder and then use a shortcode to access it like an include? Specifically, I don't understand if I am able to use shortcode as an equivalent of <php? include="myscript.php"?>.

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.