I’m wrangling a little logic problem:
I’m making a single page WP theme which uses the JSON API for the content and Mustache style templates for the presentation… However, shortcodes? What would be the best way to handle these?
For example:
JSON result->template->DOM injection->trigger hijack for gallery/slideshow/whatever the shortcode is?
The above method feels a bit dirty as I’d have to either keep firing a parser to process the shortcodes or else I’d have to use JQuery.live (seriously dirty).
Can anyone think of a more elegant way of doing this?
You can add your own AJAX API for
do_shortcode
. Add this to a suitable location (i.e.functions.php
or a plugin):And this to your Javascript:
ajaxurl
is defined on admin pages; see here for instructions for viewer-side applications.Alternatively, you can set up such actions for all API functions you need, wrapping the original calls with
do_shortcode
.