0

My pages look like this

  • Home (Has content)
  • Products (No content)
    • Product 1 (Has content)
    • Product 2 (Has content)
    • Product 3 (Has content)
  • Contact (Has content)

I only created the "Products" page so the navigation makes sense in the Pages structure, however it has no content so I need it to show the 404.php when you try to access it via the direct URL:

http://example.com/products/
1

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' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.