How to hide single pages in WordPress

This section describes how to hide single pages in WordPress. This method can be used to hide custom posts, posts, fixed pages, category pages, contributor archives, and search results pages.

To hide each single page, use the following code

// turn custom post single pages into 404 
add_filter( 'faqs_rewrite_rules', '__return_empty_array' ); 

// turn post single pages into 404 
add_filter( 'post_rewrite_rules', '__ return_empty_array' ); 

//404 fixed pages 
add_filter( 'page_rewrite_rules', '__return_empty_array' ); 

//404 category pages 
add_filter( 'category_ rewrite_rules', '__return_empty_array' ); 

//Author archive to 404 
add_filter( 'author_rewrite_rules', '__return_empty_array' ); 

//Search results page to 404 
add_ filter( 'search_rewrite_rules', '__return_empty_array' );

This code rewrites the rewrite rules for a particular page to an empty array, thereby making that page hidden (404 error).

You must save your WordPress permalink settings in order for the settings to take effect.

Reference site: here

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top