I am writing a plugin that utilizes URL parameters. For some reason, adding one of these parameters to the home page of my website causes a 404 (http://bleaney.ca/?source=asdf). Adding the parameter to any other page, however, doesn’t cause a 404 (http://bleaney.ca/work-experience-2/?source=asdf). This 404 issue only manifested itself after I registered the parameter with WordPress:
add_filter('query_vars', 'register_visitor_identifier_query_vars' );
function register_visitor_identifier_query_vars( $qvars ) {
$qvars[] = 'source';
return $qvars;
}
On the 404 page, the URL parameter is still detected by this code, the page itself just 404s for some reason:
if (isset($wp_query->query_vars['source'])) {
echo $wp_query->query_vars['source'];
}
Any idea what is causing this and how I can fix it? I think the workaround of just setting the home page to have a longer ULR like the work experience link would work, but I’d rather fix this issue if possible, rather than work around it.
I was having this same issue. I found that the issue was caused because I had set the front page to display a static page for the front page and another for the posts page. (Set in Reading Settings)
However, my posts page had been deleted. In this case because we decided not to have a posts page any more. The URL variables were trying to switch the home page view to the posts page that did not exist.
I fixed this by updating my template to use
front-page.php
(rather than a page template) and changed the setting so that the front page displaysYour latest posts
.This solution worked for me because I did not need the posts page.