Hi there,
a very handy plugin this is.
I have issues with adding parameters to the shortcodes.
So for example when I do this: [shortcode]sc_events attribute=”1″[/shortcode]
I get strange quotes that would not work if used by copy & paste. Because I am creating a documentation for the usage of all available shortcodes in a site, I need to fix this.
I just added this to the plugin code and now it does not run the filer wptexturize which cause the quotes to change.
//##### Remove filter that messes with quotes
add_filter( 'no_texturize_shortcodes', 'shortcodes_to_exempt_from_wptexturize' );
function shortcodes_to_exempt_from_wptexturize( $shortcodes ) {
$shortcodes[] = 'shortcode';
return $shortcodes;
}
Maybe this helps someone.
]]>Maybe it’s too late for this idea because people already added span.shortcode in their CSS (rather than just .shortcode which seems more likely), but it seems like your plugin would be an ideal use of the <code>
HTML tag. It’s display: inline;
like span, but would mean that all themes with CSS for <code>
magically have nice monospace fonts etc for .shortcode output.
It was easy enough for me to edit my CSS and add .shortcode
wherever I saw code
, but for people using default or off-the-shelf themes it would be a huge pain to have to copy all the code CSS into their child theme/custom-css just to get the same effect (and most won’t ever do it anyway). If you used the <code>
tag it would be automatic and they’d never even need to think about it.
Thanks again for the plugin!
]]>Hey, this is a wonderful idea and it’s great to see you made it work in such a simple way. Congrats!
My issue is that I really want to use this in image captions because when documenting shortcodes I like to insert screenshots showing the output you’d get with various attributes and having the shortcode example in the caption is the obvious way to display it.
I know it’s an annoying edge case (yo dawg, I heard you like shortcodes) but at the same time it seems like a common need for people using your plugin for it’s main purpose: documenting their shortcodes.
Right now it seems that using [shortcode] in the core [caption] doesn’t work. What I get is the caption with the unprocessed shortcode in it.
I dug around and it seems that the core img_caption_shortcode() runs do_shortcode() recursively on $content, but only after extracting the caption text and storing it in $atts[‘caption’], so shortcodes in caption text aren’t affected. This isn’t crazy since most shortcodes probably screw up the formatting.
I figured out a filter on ‘shortcode_atts_caption’ (filter atts for only caption shortcode) that very carefully enables only the [shortcode] shortcode inside image captions and only runs do_shortcode() if [shortcode] is present!
It seems like a pretty safe thing to use and makes your shortcode work in my captions. Please consider adding it to your plugin since I bet a lot of people would find it useful. Also please let me know if you discover any unintended side effects!
Here’s the code as a Gist in case the code below is broken:
https://gist.github.com/jeremyclarke/213de46aa04c95592d3e
/**
* Filter Caption shortcode attributes to enable the [shortcode] shortcode inside caption text
*
* WP doesn't run do_shortcode on the 'caption' text value parsed out of [caption], which means
* the [shortcode] shortcode doesn't work.
*
* We want [shortcode] to work but not necessarily any other shortcodes, so we will run do_shortcode()
* only if [shortcode] is present. Running do_shortcode() this way will process all shortcodes
* so beware any captions that for some reason also have a bad shortcode that will break formatting.
*
* @param array $out atts array as determined by WP to be returned after filtering
* @param array $pairs
* @param array $atts
* @return filtered $out atts
*/
function gv_filter_shortcode_atts_caption_shortcode_shortcode($out, $pairs, $atts) {
/**
* If the shortcode shortcode is present then process all shortcodes
* Note: This will process ALL shortcodes which could give insane results
*/
if (has_shortcode($out['caption'], 'shortcode')) :
$out['caption'] = do_shortcode($out['caption']);
endif;
return $out;
}
add_filter('shortcode_atts_caption', 'gv_filter_shortcode_atts_caption_shortcode_shortcode', 10, 3);
]]>