Shortcodes

By "shortcode" we of course mean a string entered into some content in a format that will be replaced by some other content when some code finds it. In Joomla when article content is being prepared the onContentPrepare event which in turn will call all active content plugins. Shortcodes sometimes contain params in their format eg. {cool_gallery 37}, and really can be as complicated or simple as you like - there's no standard. As a tip though, start and end with either braces or square brakets as they wont be interpreted when switching between html and wysiwyg in the editor.

To see how to write a content plugin look at the Content Plugins Tutorial.

Assuming we now have a content plugin set up we can now write something as follows:

class PlgContentRandomname extends JPlugin
{

    public function onContentPrepare($context, &$article, &$params, $limitstart)
    {
        $article->text = str_replace("{something}","Something else!",$article->text);
    }
}

All kinds of components can call the content plugins' onContentPrepare method, so the content allows you to run only some of the time. $content will contain something like "com_content.article".