Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

All tutorials I have found say to add your shortcodes to functions.php in your theme. I would like to break that away from my theme and put that in a plugin so I can share these shortcodes between my network of blogs. Is there a reference or tutorial on creating these shortcodes in a plugin?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Code in functions.php and plugins works in almost exactly same way (except than stage at which it is loaded and some plugin-specific hooks).

Basically you just take your code out of functions.php, place it in plugin and it still works. It is good practice to use naming conventions and checking for functions definitions so it doesn't explode if you accidentally load both copies.

But there will be no difference in how code actually works.

See Writing a Plugin for a starting point.

share|improve this answer

Basically, you just prepend your functions with a plugin header.

As a really simple example, I just put my shortcode plugin to GitHub: http://github.com/toscho/WordPress-Shortcodes

It is missing I18n – as usual :) – but it should give you some hints.

share|improve this answer
    
Wish I could mark two answers as the answer. I did upvote you. Thanks! –  Mike Wills Oct 13 '10 at 16:04
    
Wonderful use of commas when declaring an array +1+ –  brasofilo May 16 '12 at 16:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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