我已经构建了一个短代码来插入行动号召文本和按钮/链接。按钮/链接应打开带有联系人表单的模式窗口。因此,我为引导模式的按钮/链接添加了数据属性。好的但输出显示数据属性混乱。而不是data-toggle="modal"
它显示data="-" toggle="modal"
而不是data-target="#hidden-contactus-form"
it显示target="#hidden-contactus-form"
.
有什么想法吗?有什么问题吗?
我的代码:
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>\';
}
}`
另外,如果我从函数内部获取代码并将其放在模板文件中,然后用echo替换返回值,则结果是一样的。其他一切都很好,但数据属性被拆分了。