How to hide WordPress Post or Page?

How to hide WordPress Post or Page?

HIDE WORDPRESS POST OR PAGE? A STEP BY STEP GUIDE

You might have wanted to hide a WordPress page or blog post from the home page or blog archive. While you can make private, or even password-protected WordPress posts, however, sometimes when the user simply wants to hide the post from the WordPress homepage but still intend to allow some other viewers to view the post if they have a direct link. In such cases, you need to get somewhat technical and use some complex strategies.
In this article, we are going to present various ways to hide a blog post or page from the WordPress homepage, search results, category archives, and more.

Hide posts using visibility settings in WordPress

WordPress provides you an option to set the visibility for your blog post or page by default. This visibility setting is present just beneath the “Publish” button.

This setting has 3 options to hide the posts or pages completely or partially:

  • Password protected: for a particular post or page, you can set a password to hide it from other users who do not have the password. When you want other users to see your content, you can share the password with them.
  • Private: By clicking on this option, you choose to limit the visibility of the particular page or post to editors or site admins. The users not having access to the admin or editors will not be able to see the content. You can control this visibility for each post or page by assigning these roles to different personnel.
  • Public: the public setting allows everyone to access your page or post since your content is discoverable for everyone.

Hide the bulk of posts using category:

You can hide multiple pages or posts by creating a category for those pages. Activate the plugin “Show IDs by Echo Plugins” to display the IDs of your categories, pages, and posts. Once you create the category for several pages or posts you want to hide and get the category ID, simply insert the code given below in your functions.php file of the theme. This code will hide all the pages or posts in the category so they will not appear on the homepage and blog page.

function exclude_category($query) {

if ( $query->is_home() ) {

$query->set( ‘cat’, ‘- Category ID’ );

}

return $query;

}

add_filter( ‘pre_get_posts’, ‘exclude_category’ );

Hide pages or posts from particular areas of the WordPress site:

You can choose to hide your posts or pages from specific sections of the WordPress site including archive, blogroll, search results, etc. Keep reading to know these secret tricks:

  • Archive pages: Use the code below to hide individual page or post from archives:

function exclude_single_posts_archive($query) {

if ($query->is_archive() && $query->is_main_query()) {

$query->set(‘post__not_in’, array(1001, 1002,1003));

}

}

add_action(‘pre_get_posts’, ‘exclude_single_posts_archive’);

The numbers 1001, 1002, 1003 indicate IDs of pages or posts.

  • Blog roll: Use the code given below to hide your pages or posts from the blogroll section:

function exclude_single_posts_home($query) {

if ($query->is_home() && $query->is_main_query()) {

$query->set(‘post__not_in’, array(69489, 69177,68878,68736));

}

}

add_action(‘pre_get_posts’, ‘exclude_single_posts_home’);

  • Search pages: Use the code hereunder to hide the posts from the section of search pages:

function exclude_posts_pages_from_search( $query ) {

if ( ! $query->is_admin && $query->is_search && $query->is_main_query() ) {

$query->set( ‘post__not_in’, array(1001, 1002 ) );

}

add_action( ‘pre_get_posts’, ‘exclude_posts_pages_from_search’ );

  • RSS feeds: The code to hide your pages or posts from RSS feeds is given below:

function exclude_single_posts_feed($query) {

if ($query->is_feed() && $query->is_main_query()) {

$query->set(‘post__not_in’, array(69489, 69177,68878,68736));

}

}

add_action(‘pre_get_posts’, ‘exclude_single_posts_feed’);