How to Hide a Specific Post in WordPress

How to Hide a Specific Post in WordPress

Have you ever needed to hide a specific post from your WordPress homepage or blog archive page?

While it is possible to make WordPress posts password protected or private, in some cases you might simply would like to specific hide the post from your homepage while still allowing others to view it if they have the direct link.

In this blog post, we are going to show you how to hide a specific post from selected pages in WordPress. It could be your homepage, category archives, search results, and other pages.

Hide Posts from Home Page in WordPress

Method 1. How to Hide a Specific Post in WordPress
Using a Plugin

This method is easier, and it is recommended for beginners.

First thing you have to do is install and activate the WordPress Hide Posts plugin. For more details, see our step by step guide about how to install a WordPress plugin.

Once the plugin is activated, go ahead and edit the post you would like to hide. You will notice a new ‘Hide Posts’ section in the right column of the editor.

Simply clicking on it will reveal plugin options. You will be able to hide the post on the front page and blog page, category or tag pages, authors page, and website search results.

Simply select the options you like and after that save your post.

Based on the options you selected, you can now visit those pages and that particular post will not be listed.

Only users who have the direct post URL (permalink) will be able to still see it by entering the URL.

While this method certainly is the easiest, it lacks several powerful options.

For example, you will not be able to hide a page or even custom post type like a WooCommerce products. It also does not have an option to hide a post from WordPress RSS feed.

Method 2. How to Hide a Specific Post in WordPress
Manually

This method requires you to add code to your WordPress website. In case you have not done this before then see our guide about how to copy and paste code snippets in WordPress.

WordPress uses a database query to fetch and show posts based on the page a user is viewing. It also provides built-in hooks to modify the query before running it.

we are going to be using those hooks to modify the WordPress query and hide the WordPress posts, pages, and custom post types in different sections.

You will be able to add custom code using the code snippets plugin which is safer and does not break your WordPress website. Alternatively, you will be able to add the custom code to your theme’s functions.php file.

You will also have to know the IDs of the post or pages which you would like to hide. We have got a quick tutorial about how to find a post ID in WordPress that shows how to find a post ID.

Basically, you will be able to just edit a post or page to view its ID in your browser’s address bar.

Finding a post ID in the address bar

That being said, let us dive into the code part.

Hide WordPress Posts or Pages from Homepage

The following code uses is_home() conditional tag to find out when the user is viewing the homepage. If they are, then it excludes the post IDs from the query.

function wpb_exclude_from_home($query) {<br />if ($query-&gt;is_home() ) {<br />$query-&gt;set('post__not_in', array(1737, 1718));<br />}<br />}<br />add_action('pre_get_posts', 'wpb_exclude_from_home');

Do not forget to replace the IDs inside the array with the actual IDs of posts or pages which you would like to exclude.

Hide WordPress Posts or Pages from RSS Feed

In case you would like to hide a WordPress post from the homepage as well as the WordPress RSS feed, then you have to simply use the is_feed conditional tag in the code.

function wpb_exclude_from_feed($query) {<br />if ($query-&gt;is_feed() ) {<br />$query-&gt;set('post__not_in', array(1737, 1718));<br />}<br />}<br />add_action('pre_get_posts', 'wpb_exclude_from_feed');

Now if you are logged in as an administrator and tried to visit your WordPress RSS feed, then you will still see the posts listed there. Other users will not be able to see the excluded posts when they view your RSS feed.

Hide WordPress Post or Page from Website Search

Now, what if you wanted to hide specific posts from WordPress website search? To do that, you will simply have to add the is_search conditional tag to the code.

function wpb_exclude_from_search($query) {<br />if ( $query-&gt;is_search() ) {<br />$query-&gt;set('post__not_in', array(1737, 1718));<br />}<br />}<br />add_action('pre_get_posts', 'wpb_exclude_from_search');

You can now visit your WordPress website and look for the posts you wanted to hide. Even though these posts are public, they will not appear in search results.

Post excluded from search results

Hide WordPress Post or Page from Archives

How about hiding specific WordPress posts or pages from archive pages like category, tags, and date archives? To do that, we will have use the is_archive() conditional tag.

function wpb_exclude_from_archives($query) {<br />if ( $query-&gt;is_archive() ) {<br />$query-&gt;set('post__not_in', array(1737, 1718));<br />}<br />}<br />add_action('pre_get_posts', 'wpb_exclude_from_archives');

Hiding WordPress Post or Page from Everywhere

So far we have learned {how to|how you can|the best way to|the way to} hide a WordPress post or page from specific areas. Now, what about completely hiding a WordPress post from {all these|all of these} areas at once?

To do that, you will have to combine all the conditional tags we have used earlier in a single code snippet.

function wpb_exclude_from_everywhere($query) {<br />if ( $query-&gt;is_home() || $query-&gt;is_feed() || $query-&gt;is_search() || $query-&gt;is_archive() ) {<br />$query-&gt;set('post__not_in', array(1737, 1718));<br />}<br />}<br />add_action('pre_get_posts', 'wpb_exclude_from_everywhere');

This code will hide the given posts from homepage, RSS feed, search results, and archive pages.

We hope this blog post helped you learn How to Hide a specific Post in WordPress homepage and other pages of your WordPress website. You might also want to see our guide about how to make a WordPress website completely private.

In case you liked this blog post, then please sign up to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

RoundCodeBox is a leading Custom Software Development Company. RoundCodeBox specializes Web development, Web Application Development, eCommerce Website Development, WordPress Website Development. Apart from offering our clients development services we also contribute to the open source community on regular basics.

Subscribe Now

Don’t miss our future updates! Get Subscribed Today!

[contact-form-7 404 "Not Found"]

©2020. RoundCodeBox. All Rights Reserved.

How to Exclude a Category From Your WordPress Homepage

How to Exclude a Category From Your WordPress Homepage

How to Exclude a Category From Your WordPress Homepage

How to Exclude a Category From Your WordPress Homepage

Do you want to exclude a specific category from your website’s homepage? By default, WordPress displays posts from all categories on your own homepage. In some cases, you might not want that. In this blog post, we are going to show you how you can very easily exclude a category from your WordPress homepage.

Why Exclude a Category from WordPress Homepage?

WordPress enables you to sort content into categories and tags. Now sometimes you might want to use a category for posts that are not part of your normal blog entries.

By default, WordPress will not let you to hide posts in specific categories from homepage or archives. This leaves you with unwanted posts appearing on your homepage.

That being said, let us see how you will be able to easily exclude a specific category from your WordPress homepage. we are going to show you two different methods, and you will be able to select the the one which best fits your needs.

Method 1: Exclude a Category from WordPress Using Plugin

First thing you have to do is to install and activate the Ultimate Category Excluder plugin. For more details, you should follow our guide about how to install a WordPress plugin.

Upon activation, you will have to go to Settings » Category Excluder page. It will show all the categories that are available on your WordPress website.

From here, you will be able to simply check one or multiple categories under the ‘Exclude from front page’ column. In case you want, then you will be able to also exclude the category from RSS feeds, archives, or even from WordPress search.

Do not forget to click on the Update button to store these settings.

Now you will be able to visit your website to view that the posts from the selected categories are excluded from the front page.

Method 2: Exclude a Category from WordPress Homepage Using Code

This method requires you to add code to your WordPress files. In case you have not done this before, then see our guide about how to copy and paste code snippets in WordPress.

You have to add following code to your theme’s functions.php file or perhaps a site-specific plugin.

<br />function exclude_category_home( $query ) {<br />if ( $query-&amp;gt;is_home ) {<br />$query-&amp;gt;set( 'cat', '-3' );<br />}<br />return $query;<br />}<br />add_filter( 'pre_get_posts', 'exclude_category_home' );<br />

Do not forget to replace ID (-3) with your category ID. It will hide all blog posts from homepage belonging to the category that matches this ID.

Note: Make sure to add a minus (-) sign with the category ID.

Not sure how you can find the category ID? See our guide about how to find category IDs in WordPress.

In case you wish to exclude multiple categories, then you to change the code like this:

function exclude_category_home( $query ) {<br />if ( $query-&gt;is_home ) {<br />$query-&gt;set( ‘cat’, ‘-3, -9, -21’ );<br />}<br />return $query;<br />}<br />add_filter( ‘pre_get_posts’, ‘exclude_category_home’ );

Simply replace the IDs (-3, -9, -21) with your category IDs to exclude them from your WordPress homepage.

We hope this blog post helped you learn how to exclude a category from your WordPress homepage. You might also want to see these most wanted category hacks and plugins for WordPress that will help you use categories much more efficiently.

In case you liked this blog post, then please sign up to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Also published on Medium.

RoundCodeBox is a leading Custom Software Development Company. RoundCodeBox specializes Web development, Web Application Development, eCommerce Website Development, WordPress Website Development. Apart from offering our clients development services we also contribute to the open source community on regular basics.

Subscribe Now

Don’t miss our future updates! Get Subscribed Today!

[contact-form-7 404 "Not Found"]

©2020. RoundCodeBox. All Rights Reserved.

How to Create a Table of Contents in WordPress Posts and Pages

How to Create a Table of Contents in WordPress Posts and Pages

How to Create a Table of Content in WordPress Posts and PagesDid you ever want to add a Wikipedia like table of contents box on some of your long articles? A table of contents makes it easier for users to jump to the section they would like to read. In this blog post, we are going to show you the best way to create a table of contents in WordPress posts and pages without the need of writing any HTML or CSS.

Why Add a Table of Contents in WordPress Posts and Pages?

You might have seen the table of contents on websites like Wikipedia. A table of contents makes it easier for users to jump to the section they would like to read in long articles.

It also helps with your WordPress SEO because Google automatically adds a jump to section link next to your website in search results.

You’ll be able to manually create a table of contents in WordPress by writing HTML code. However which is difficult for beginners because you will have to manually create a list, add links, and add ID attribute through-out the article.

However there’s an simple and easy way. Let us have a look about how to easily create a table of contents in WordPress posts and pages.

Creating a Table of Contents in WordPress

First thing you should do is to install and activate the Easy Table of Contents plugin. For more details, see our detailed guide regarding how to install a WordPress plugin.

Upon activation, you have to visit Settings » Table of Contents page. From here, you will be able to manage general settings for the table of contents like selecting position, choosing a label for the container, etc.

How to add a Table of Contents in WordPress Posts and Pages

You will be able to also enable or disable auto-insertion of the table of contents for each and every post type. If enabled, then the plugin will automatically add a table of contents for any article that has more than 4 headings. You will be able to change/modify that to any other number which you like.

Generally, we do not recommend adding a table of contents on every article unless all of your articles are really long.

Next, you will be able to scroll down to modify the appearance of the table of contents box. From here you will be able to pick a theme, adjust width and height, set the font size, or create a custom color scheme for your table of contents box.How to add a Table of Contents in WordPress Posts

After that, you have to go to the Advanced settings section. The default options would work for the majority of websites, however you will be able to review these options to view in case you would like to adjust anything.

How to add a Table of Contents in WordPress PagesDo not forget to click on the Save Changes button to store these settings.

Adding a Table of Contents to WordPress Posts or Pages

Unless you have disabled the auto-insertion, the plugin will now automatically start adding a table of contents to posts based on settings you chose earlier. You will be able to also manage the settings on a post by post basis.

On the post edit screen, you will notice a new section to include and manage the table of contents to your post.

In this section, you will be able to disable auto-insert option for the table of contents on this post specifically. You can also choose which heading level to use for the table items.

Note: In case you modify any setting in this box, then it will override the global settings for this specific post / page.

Once you have written the article with multiple headings, you will be able to simply preview it to view the Table of Contents in action.

The table of contents will appear just above the first heading in your article. Your readers can easily click on links and jump to the section they would like to read.

We hope this blog post helped you quickly learn how to create a table of contents in WordPress posts and pages. You can visit our blog to read more blog posts.

If you liked this blog post, then please subscribe to our YouTube Channel for WordPress video tutorials. You will be able to also find us on Twitter and Facebook.

RoundCodeBox is a leading Custom Software Development Company. RoundCodeBox specializes Web development, Web Application Development, eCommerce Website Development, WordPress Website Development. Apart from offering our clients development services we also contribute to the open source community on regular basics.

Subscribe Now

Don’t miss our future updates! Get Subscribed Today!

[contact-form-7 404 "Not Found"]

©2020. RoundCodeBox. All Rights Reserved.