Multiple 404.php templates based on a post_type

It is possible but wordpress doesn’t have any helpful constructs to help with that. The best approach is to modify your 404.php. Most of the information that you need should be in the main WP_query object and you should be able to do something like if (is_singular(‘post_tyoe_a’)) { …. } else { …. } this … Read more

Fix 404 error after changing permalink structure

If your .htaccess file were writable, wordpress do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your .htaccess file. 1- Open .htaccess file and copy following data in that file. <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . … Read more

Need 404 behaviour for blank parent page

In functions.php function productsPageRedirect_404() { global $post; if( is_page(‘products’) ) { global $wp_query; $wp_query->set_404(); status_header(404); } } add_action( ‘wp’, ‘productsPageRedirect_404’ );

No 404 page available

There is 404.php in the theme uploaded. But when there is search for non-existent page. The 404.php does not show up. When there is search for non-existent page doesn’t produce the 404 page, but simply shows the search.php‘s else portion. A simple search.php is like: <?php if( have_posts() ) : ?> <?php while( have_posts() : … Read more

404 not working on main site on multisite

The cause of your problems is this line: define( ‘NOBLOGREDIRECT’, ‘http://www.ncc.my’ ); If a user visits a blog that doesn’t exist, e.g. http://example.ncc.my this is where the user is sent. However there are also sub directory installs, so all requests that aren’t found are sent there. The easy fix would be to set up a … Read more

All attachment pages give 404

Actually I got to the bottom of it. The problem was that I have installed the WPML plugin. But I forgot to install the WPML Media plugin. As soon as I installed it, the attachment pages started working again. In my opinion, this is unacceptable and I will escalate the issue to WPML team. If … Read more

is_404() – where does this get set?

There is a dedicated method for it WP_Query->set_404(). From quick search through code it can be set in WP_Query->parse_query() or WP->handle_404() (note WP, not WP_Query!). But it can (and sometimes does) get set on query externally, for example by plugin that needs to invalidate specific resource.