Timeline for Conditionally Loading JavaScript/CSS for Shortcodes
Current License: CC BY-SA 3.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Feb 9, 2012 at 18:35 | comment | added | TheDeadMedic |
@Bainternet Not neccessarily - preg_match vs stripos (case-insensitive) - either way we're talking petty timings. In hindsight, I think I should have avoided the term "faster" - really I was trying to imply it was more efficient for the task in hand (as opposed to multiple stripos for accomodating various shortcode formats).
|
|
Feb 5, 2012 at 17:57 | comment | added | Bainternet |
Nice but i have to disagree on the preg_match beeing faster the strpos lzone.de/articles/php-string-search.htm
|
|
Jun 26, 2011 at 5:41 | comment | added | TheDeadMedic | @Ian Nice! Thanks for coming back with an update, both for us and the googlers that land on it later ;) | |
Jun 26, 2011 at 5:27 | comment | added | Ian Dunn | @TheDeadMedic - I got it integrated with my code and updated the question w/ links to it in case anyone wants to see it fleshed out. Thanks again for your help :) | |
Jun 24, 2011 at 1:10 | vote | accept | Ian Dunn | ||
Jun 23, 2011 at 23:03 | comment | added | Chip Bennett |
@Ian my thinking was that adding do_shortcode() to the template is already "do[ing] something extra" - and users that would do that something-extra would either already know about the need to enqueue the style, or else would be more willing/likely to follow special instructions.
|
|
Jun 23, 2011 at 22:05 | comment | added | Ian Dunn | @Chip - I'm not worried that they're not capable of following the instructions, just that they won't know they're supposed to, since 99% of the time you don't need to do anything extra. | |
Jun 23, 2011 at 19:25 | history | edited | TheDeadMedic | CC BY-SA 3.0 |
added 489 characters in body; added 10 characters in body
|
Jun 23, 2011 at 19:17 | comment | added | TheDeadMedic |
True, but it'll get the regex for all shortcodes, not just yours ;) "I could register the scripts on every page" Probably the better method too! Note they don't need to hook into init , just anywhere before wp_head . For the lazy developer, check wp_style_is( 'my_style_handle', 'done' ) inside your shortcode. If it's false, print out a visible error that instructs them what to do.
|
|
Jun 23, 2011 at 19:16 | comment | added | Chip Bennett |
If users are adept at implementing do_shortcode() , is it not reasonable to assume that they are likewise adept at following instructions for enqueueing the shortcode style?
|
|
Jun 23, 2011 at 18:54 | comment | added | Ian Dunn | That's a good point. Ideally I'd like it to work without them having to do anything extra -- because half the time they probably won't read the FAQ first, so they'll just assume it's broken -- but I might end up doing that. I could register the scripts on every page, but only enqueue them if I detect a shortcode. Then, users could hook into init and call the enqueue functions in specific templates where needed, assuming it's not already too late in the execution at that point. Also, WP has get_shortcode_regex() built-in. | |
Jun 23, 2011 at 18:23 | history | answered | TheDeadMedic | CC BY-SA 3.0 |