When a link doesn’t exist, how to tell WordPress what to do? (404 Error Page)

The conditional you use to output get_template_part(‘content’, ‘none’); is only triggered if there is no post in the main loop, for example, when a category has no posts in it: if (have_posts()){ while(have_posts()) { the_post(); // If the category has a post and we are on a category page, then show the posts get_template_part(‘content’, ‘archive’); … Read more

How To Create A Custom Taxonomy 404 Page

You can filter any type of template to override the template hierarchy. In this case the filter is 404_template. We’ll check if the location query var is set, meaning the URL matched the pattern of a location request, but the result was a 404. In that case, we’ll load the 404-taxonomy-location.php template. function wpd_custom_tax_404( $templates … Read more

Getting a 404 error when clicking edit page

You mentioned that you disabled all plugins, and changed the theme (I assume you used one of the ‘twenty’ themes, which is what I usually do when trying to find theme/plugin problems). Did you also look at the ‘must use’ plugins (in wp-content/mu-plugins ) (see https://codex.wordpress.org/Must_Use_Plugins ). Maybe a plugin in there is causing problems. … Read more

Non-existent page returns code 200

That’s not what’s happening, when you visit /contacts–/ it doesn’t return a 200 code, but instead it returns a 301 redirect code. The browser then follows this redirect and heads to /contact and it’s /contact that returns 200 code. This is because /contact is the canonical URL of that page, and WordPress redirects to canonical … Read more

Redirect a page id url but not the page slug

Try using the pre_handle_404 hook instead: add_filter( ‘pre_handle_404’, ‘wpse_383506’, 10, 2 ); function wpse_383506( $preempt, $wp_query ) { if ( ! empty( $_GET[‘page_id’] ) && ‘342’ === $_GET[‘page_id’] ) { // Throw a 404 error. $wp_query->set_404(); // And prevent redirect to the page permalink (pretty URL). remove_action( ‘template_redirect’, ‘redirect_canonical’ ); } return $preempt; // always … Read more