I have a site that is performance critical. Doing shortcodes I thought about the time the server needs to parse and return the content, instead to allow some HTML (<div class="redletter">
) to go through the TinyMCE editor. In the meantime, my code for that is:
// [redletter]Content[/redletter]
add_shortcode('redletter', 'redletter_do');
function redletter_do($atts, $content = null) {
return '<div class="redletter"' . do_shortcode($content) . '</div>';
}
Performance critical or not, I think that nothing could beat a button to allow a <div>
pass through directly in the visual editor and show – like it does when you press the [B] button to make <strong>
.
So, i’m between keeping the shortcode, or making a TinyMCE button for <div class="redletter">
and showing the result in the visual editor.
I’d say make the button–but not for performance reasons.
I think if you benchmark it, you’ll find that any performance overhead added by running a simple function like this (one that does some simple string concat) is quite minimal. Or, at least, down to fractions of fractions of a second on a decent server.
If you’re under very high load, and are worried about performance at this level, you should probably focus on a good caching layer and a fast server. We (and by we I mean our awesome sysadmin guy) have recently been playing with an nginx / varnish setup, and it’s boosted performance to an unbelievable degree. (See this guy, who got it to work very well)
Of course, it’s not a silver bullet, and you should always have an eye toward reducing the number of queries run, requests made, etc. So I get your intent. The kind of functionality you’re attempting with this question is admirable (a TinyMCE button is a MUCH better user experience than a shortcode), but I don’t think it’ll help much when it comes to performance.