我正在尝试将 URL GET 参数添加到我在 Wordpress 中的主菜单项之一(但我不知道如何)。因此,我的方法是检测菜单项上的单击事件,然后通过 ajax 将参数传递给我的 php 页面,该页面将根据需要处理传递的值。我的主要问题是,看看我的代码,为什么不工作?有没有更好的方法在 Wordpress 中做到这一点而不依赖于 javascript?
Here is the javascript:
<script type="text/javascript">
$(document).ready(function() {
$("#menu-item-128").click(function() {
$.ajax({
url: 'homepage.php',
type: "GET",
data: ({ homeclick = true }),
success: function() {
alert("success!");
}
});
});
});
</script>
Here is my PHP:
$homeclick = $_GET['homeclick'];
if ( !isset( $_COOKIE['hs_user'] ) ) {
get_header();
} elseif (isset( $_COOKIE['hs_user'] ) && $homeclick == true ) {
get_header();
} else {
// Do Something else
header('Location: homepage-returning-users');
}