I have build a shortcode to insert a call to action text and button/link. The button/link should open a modal window with a contact form. So I added data attributes to the button/link for Bootstrap modal.
Fine.
But the output shows the data attributes messed up. Instead of data-toggle="modal"
it shows data="-" toggle="modal"
and instead of data-target="#hidden-contactus-form"
it show target="#hidden-contactus-form"
.
Any ideas what could be wrong?
My code:
add_shortcode('kontakt', 'insertcontactcta');
function insertcontactcta($attr, $content ) {
global $sitepress;
$current_language = $sitepress->get_current_language();
if($current_language == 'de'){
$optionLang = '';
}elseif($current_language == 'en'){
$optionLang = '_en';
} if($global_cta_text = get_option('options'.$optionLang.'_global_cta_text')){
$globalCTAText = '<p>'.$global_cta_text.'</p>';
}else{
$globalCTAText = '';
}
if($global_cta_linktext = get_option('options'.$optionLang.'_global_cta_linktext')){
$globalCTALinktext = $global_cta_linktext;
}else{
$globalCTALinktext = '';
}
if($global_cta_link = get_option('options'.$optionLang.'_global_cta_link')){
$globalCTALink = '<div class="cta-linkwrap"><a class="cta-btn" data-toggle="modal" data-target="#hidden-contactus-form" href="'.$global_cta_link['url'].'">'.$globalCTALinktext.'</a></div>';
}else{
$globalCTALink = '';
}
$modalWrapper = '<div id="hidden-contactus-form" class="modal" tabindex="-1" role="dialog" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button></div><div class="modal-body"></div><div class="modal-footer"></div> </div></div></div>';
if($globalCTAText != '' && $globalCTALink != ''){
return '<div class="cta-insert col-12 ml-auto mr-auto">'.$globalCTAText.$globalCTALink.$modalWrapper.'</div>';
}
}`
P.S. If I take the code from inside of the function and put it in a template file and replace the return with echo, it's the same. Everything else is fine, but the data-attributes are ripped apart.