0

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.

5
  • 1
    Can you share your shortcode code?
    – kero
    Nov 27, 2020 at 13:16
  • I added my code to the post.
    – AdSim
    Nov 30, 2020 at 8:15
  • Ok, I found the problem. I use a plugin called Remove Redundant Links and it seems to mess around with the data attributes.
    – AdSim
    Nov 30, 2020 at 10:23
  • @AdSim can you post that as an answer?
    – Tom J Nowell
    Nov 30, 2020 at 10:56
  • 1
    @TomJNowell Done.
    – AdSim
    Nov 30, 2020 at 11:01

1 Answer 1

2

Ok, I found the problem. I use a plugin called Remove Redundant Links and it seems to mess around with the data attributes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.