WordPress 2.5 Shortcode API introduced
WordPress 2.5 introduces the new new ‘Shortcode’ API for developers to create macro codes to insert into posts and content. This is an exciting new feature, which when teamed up with the features of TinyMCE v3 (also new to WordPress 2.5) offers developers a whole new way to insert all manner of clever things into posts - potentially with just a click of a new TinyMCE button (if you created one)… cool!
The TinyMCE development is for another time, the WordPress Shortcode API is best explained by example. The most basic example looks like [myshortcode] in your post content, although they may also take the form of [myshortcode variable1="option1" other="12345" another="data"] or [myshortcode]Content here[/myshortcode].
Xavisys have written an excellent article that gives a clear explanation of Shortcodes. It also gives a great example of adding a new menu item to the editor screen and creating a form for more complex shortcodes with lots of variables and formatting.
Relevant links and further reading
WordPress 2.5.1 released - security update »
Comments
Comment from Jonny
Time: October 20, 2008, 12:59 pm
@ Numismatic - nice tip, thanks for contributing… sounds like a great way to implement shortcode elsewhere, cheers!







Comment from Numismatic
Time: October 9, 2008, 10:17 am
The wordpress shortcodes will work only by default on posts and pages. You could add this statement add_filter(’widget_text’, ‘do_shortcode’); to your wordpress themes functions.php file to make the shortcodes work in the Text Widget. You will need to replace “do_shortcode” with the name of your shortcode function.
To use your shortcodes outside of posts, pages, and the text widget, you could always call your shortcode function directly like this:
[code]
$text = yourShortCodeFunction(’[your shortcode tag here]‘);
echo $text;
[/code]
I’m not sure if the code will display here, always have problems posting code.
Very informative blog, lots of information.