Codeigniter – Shortcodes library (yet another)


There are a few short-code libraries out there already for Codeigniter but for the project I am currently working on I needed a bit more control. Here is my solution for implementing a short-codes system similar to the one built into WordPress.

Each short-code is surrounded by double square brackets ( [[ … ]] ), with the content of the short-code consisting of a key and a value broken up by a double colon ( :: ). An example of how an internal link might be implemented is:

[[internal::contact us]]

The library does not try to do anything clever, it just maps over a string the references to all short-codes, their key / values pairs, lengths, start and ends. There are utility functions that allow specific short-codes to be replaces with HTML snippets.


This is an example of how to incorporate the code into a Codeigniter project:


Here is the library code: