通常,您不需要在网站底部放置模式代码。因此,您可以直接在切换器之前或之后编写它。
如果你真的想把它放在底部,那就更复杂了。
因为我们需要从短代码中获取属性,所以不能调用wp_footer
直接勾住。因此,我们需要编写一个过滤器,在页脚中显示模式。
以下是一个示例:
function draw_footer_modal($modal_id) {
add_action(\'wp_footer\', function () use ($modal_id) {
?>
<div class="modal fade" id="<?= $modal_id; ?>" tabindex="-1" role="dialog" aria-labelledby="<?= $modal_id; ?>\'Label" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content subscribe-fields">
<div class="modal-body">
<div class="fullframe">my modal is here! </div>
</div>
</div>
</div>
</div>
<?php
});
}
add_filter(\'draw_a_modal\', \'draw_footer_modal\', 10, 1);
function action_button_shortcode($atts, $content = null) {
extract(shortcode_atts(
array(
\'title\' => \'Title\',
\'color\' => \'blue\', // blue, green
\'url\' => \'url\',
\'icon\' => \'arrow\', // arrow, download, email, search, account, lock
\'level\' => \'primary\', // primary, secondary, tertiary
\'target\' => \'self\', // blank, self
),
$atts
));
if ($target == \'modal\') {
do_action(\'draw_a_modal\', \'#modal\' . url_to_postid($url)); // Apply the action here
return \'<span class="byn-btn btn-\' . $level . \' bg-\' . $color . \' icon-\' . $icon . \'" data-toggle="modal" data-target="#modal\' . url_to_postid($url) . \'"><span>\' . $title . \'</span></span>\';
} else {
return \'<a href="\' . $url . \'" class="byn-btn btn-\' . $level . \' bg-\' . $color . \' icon-\' . $icon . \'" target="_\' . $target . \'"><span>\' . $title . \'</span></a>\';
}
$content = wpautop(trim($content));
}
add_shortcode(\'ci-action-button\', \'action_button_shortcode\');
我建议将
id
变量中的属性,以避免在
target
属性,而不是
id
属性