Hi there. I have been trying to get a simple shortcode to work, but have been unable. The shortcode is to output html to show an image in a lightbox modal, in bootstrap 4. That is, it uses bootstrap 4 classes. Here is my code:
I'm calling the shortcode like this, in my page:
The problem is that the parameters are not parsed into the different variables, but rather all appear in "imgscr".
This must be something simple that I just can't see. Can someone help please?
- Code: Select all
$FUNCS->register_shortcode( 'bsmodal', 'bsmodal_handler' );
function bsmodal_handler( $params, $content=null ){
global $FUNCS;
extract( $FUNCS->get_named_vars(array(
'imgsrc' => '',
'imgalt' => '',
'myid' => '',
'maxwidth' => '300'
), $params) );
$imgsrc = str_replace("\xc2\xa0", " ", $imgsrc);
$imgalt = str_replace("\xc2\xa0", " ", $imgalt);
$imgsrc = htmlspecialchars( $imgsrc, ENT_QUOTES );
$imgalt = htmlspecialchars( $imgalt, ENT_QUOTES );
$maxwidth = (int)$maxwidth;
if ($maxwidth) $maxwidth=";max-width:${maxwidth}px";
$html =<<<EOS2
<div class="modal bd-example-modal-lg" id='modal-$myid' role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="dynamic-content">
<img src='$imgsrc' class="img-fluid" alt="$imgalt"/>
</div>
</div>
</div>
<a><img class='modal-img' src='$imgsrc' alt='$imgalt' style='width:100%${maxwidth}' data-toggle="modal" data-target="#modal-$myid"></a>
</div>
EOS2;
return $html;
}
I'm calling the shortcode like this, in my page:
- Code: Select all
[bsmodal imgsrc='/path/to/image with spaces.jpg' imgalt='Image description' myid='id1']
The problem is that the parameters are not parsed into the different variables, but rather all appear in "imgscr".
This must be something simple that I just can't see. Can someone help please?