【发布时间】:2021-05-19 00:52:31
【问题描述】:
我对 Wordpress 短代码和 Elementor 有疑问。假设我在functions.php 中有以下短代码:
function some_shortcode($atts) {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
echo 'It works!';
}
}
add_shortcode('shortcode', 'some_shortcode');
接下来,我使用 Elementor 将以下 HTML 代码放入页面:
[shortcode]
<form method="POST">
<button type="submit">Click me</button>
</form>
我真的很喜欢短代码函数仅在用户单击表单按钮时执行(所以当 POST 方法发生时)但事实上,短代码一直在执行(看起来如果短代码函数内部的条件不起作用)。请你告诉我,我怎样才能让简码只有在点击表单按钮后才能工作?
【问题讨论】:
标签: php wordpress shortcode elementor wordpress-shortcode