URL parameters causing 404 on home page, but nowhere else

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:

Read More
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.

Related posts

1 comment

  1. 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)

    enter image description here

    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 displays Your latest posts.

    enter image description here

    This solution worked for me because I did not need the posts page.

Comments are closed.