我正在尝试将URL GET参数添加到Wordpress中的一个主菜单项(但我不知道如何).所以,我的方法是检测菜单项上的click事件,然后通过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');
}
Run Code Online (Sandbox Code Playgroud)