Skip to content
umefarooq edited this page Oct 9, 2011 · 5 revisions

Wordpress is amazing CMS, shortcodes is an interesting API which make wordpress more amazing just put tags in you content will be parsed by shortcodes and gives you formatted output of your content, now this shortcode api is now ported to FuelPHP framework a really good framework to develop and deploy application really fast. here how shortcodes work in FuelPHP.

short tags in view or content from admin

here is simple example of short tag with foo bar

[footag foo="bar"]

above short tag has the following points just like normal HTML tags

  1. [ start of tag
  2. footag tag name
  3. foo="bar" tag attributes 4 ] end or close tag

Using shortcode in controller

To process above tag in view or content and make it proper out put we need to add tag name and attach a method which will format this tag name.

Shortcode::add('footag', 'Codes::footag_func');

above code we are calling add function of shortcode class adding tag name and function attached to this tag name.

render view output

$html = render('welcome/index');

now process the shortcodes

$this->response->body = Shortcode::run($html);

run method of shortcode class will process all short tags with their attached shortcode function will return formatted output.


define shortcodes in config

you can add shortcodes in config file

    'codes' => array(
        'tabgroup' => 'Codes::jqtools_tab_group',
        'tagname' => 'Codes::tag_attached_function'
    )
);```

here is example short tag for jquery tabs 

http://scrp.at/avM

attached function is already part of shortcode package.

for more information you can use wordpress shortcodes API

http://codex.wordpress.org/Shortcode_API