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.

404 redirect based on url

I would use the wp hook, which fires right after the request has been parsed and queried: function wpse_199869_wp( $wp ) { if ( ! is_admin() && is_404() && preg_match( ‘/^bh-job/’, $wp->request ) ) { wp_redirect( home_url( user_trailingslashit( ‘jobs’ ) ) ); exit; } } add_action( ‘wp’, ‘wpse_199869_wp’ ); We make sure it’s a 404, … Read more

Multisite 404 page

The easiest way is to check for get_current_blog_id(); and adjust your 404 template based on the current blog id. An other option is creating a child theme for every site and adding different page-404 templates.

Direct form to a custom page template

A helpful clue would be to look at the URL in the address bar of your 404 page. A reliable approach for form action in WP looks like the snippet below. <form method=”post” id=”thisform” action=”<?php bloginfo(‘url’); >/dbsearch/”> I would create your page in WP, ensure the page slug is ‘dbsearch’ as this determines your permalink … Read more

Redirect to parent page if child does not exist

If you want to do this in your .htaccess file to ensure an early redirect, the method is as follows. First check if the page does not exist using the rewrite condition: RewriteCond %{REQUEST_FILENAME} !-f Next comes the rewrite rule for the page that does not exist RewriteRule ^/au/location1/(.*)$ http://example.com/au/location1/ [L] Putting this all together: … Read more