Space in WordPress Attribute Causing Problems
Question
I’m trying to write my first caption plugin and having some difficulties.
I’m setting up a shortcode like so:
function Shortcode_Caption( $atts, $content=null ){
// DEFAULT ARGUMENTS ARRAY
$args=shortcode_atts( array(
'caption' => 'Caption',
'link' => 'http://www.link.com'
), $atts);
// ENCLOSED SHORTCODES
if($content){
return '<div class="Container-Caption"
alt="'. $args['caption'] .'"
rel="'. $args['link'] .'">
'.$content.'</div>';
};
};
add_shortcode( 'Caption', 'Shortcode_Caption' );
Some JS picks it up from there. So then when the shortcode is used:
[Caption caption="This is the Text" link="http://www.go_here.com"]some content[/Caption]
The above doesn’t work, because of the spaces in the “caption” attribute. However, removing the spaces works 100%:
[Caption caption="Text" link="http://www.go_here.com"]some content[/Caption]
I’m not sure what I’m doing wrong with this?
Thanks!
0
plugins, shortcode
4 years
2020-02-15T08:39:17-05:00
2020-02-15T08:39:17-05:00 0 Answers
89 views
0
Leave an answer