This is actually more complicated than it might seem on the surface. Andrew answers, but begins to break down if square brackets appear in the source text [for example, this]. WordPress works by pre-registering a list of valid shortcodes and only acting on the text inside the brackets if it matches one of these predefined values. Thus, it does not distort any plain text that could have a set of square brackets in it.
The actual source code for the WordPress shortcode engine is strong enough, and it doesn't seem like it would be very difficult to modify the file to run on its own - then you can use this in your application to handle the tough work. (If you're interested, see get_shortcode_regex() in this file to see how hairy the correct solution to this problem can be.)
A very crude implementation of your question using WP shortcodes.php will look something like:
// Define the shortcode function inlude_shortcode_func($attrs) { $data = shortcode_atts(array( 'file' => 'default' ), $attrs); return "Including File: {$data['file']}"; } add_shortcode('include', 'inlude_shortcode_func'); // And then run your page content through the filter echo do_shortcode('This is a document with [include file="header.html"] included!');
Again, not tested at all, but it is not a very hard API to use.
smitelli
source share