Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPBカップ
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

カテゴリー:WordPressでトップページから投稿を非表示にする方法

編集メモ: WPBeginner のパートナーリンクから手数料を得ています。手数料は編集者の意見や評価に影響を与えません。編集プロセスについて詳しく知る。

WordPressのホームページやブログのアーカイブページからブログ投稿を非表示にしたいと思ったことはありませんか?

WordPressの投稿をパスワードで保護したり、非公開にすることはできますが、場合によっては、単に投稿をホームページから非表示にしたいだけで、他の人が直接リンクを持っていれば、その投稿を表示できるようにしたいこともあるでしょう。

この記事では、トップページ、カテゴリーアーカイブ、検索結果など、WordPressで選択したページから投稿を非表示にする方法を紹介する。

Hide Posts from Home Page in WordPress

ここでは、ホームページから投稿を非表示にする2つの異なる方法について説明します。以下のクイックリンクから、使いたい方法に直接ジャンプできます:

方法1.プラグインを使ってWordPressの投稿を非表示にする。

この方法は簡単で、初心者にお勧めだ。

最初に行う必要があるのは、WordPress Hide Postsプラグインをインストールして有効化することです。詳しくは、WordPressプラグインのインストール方法のステップバイステップガイドをご覧ください。

プラグインを有効化したら、非表示にしたい投稿を編集します。エディターの右カラムに新しく「非表示投稿」セクションが追加されていることに気づくでしょう。

Hide posts settings

クリックするとプラグインのオプションが表示されます。トップページやブログページ、カテゴリーやタグページ、投稿者ページ、サイト内検索結果の投稿を非表示にすることができます。

お好きなオプションを設定し、投稿を保存するだけです。

選択したオプションによっては、それらのページにアクセスしても、特定の投稿が表示されなくなります。

直接投稿URL(パーマリンク)を持っているすべてのユーザーは、URLを入力することでその投稿を見ることができます。

この方法は最も簡単だが、いくつかの強力なオプションが欠けている。

例えば、ページやWooCommerce商品のようなカスタム投稿タイプを非表示にすることはできません。また、WordPress RSSフィードからの投稿を非表示にする設定もありません。

方法2.WordPressの投稿とページを手動で非表示にする。

この方法では、WordPressサイトにコードを追加する必要があります。WordPressでコード・スニペットをコピー&ペーストする方法をご覧ください。

WordPressは、ユーザーが表示しているページに基づいて投稿を取得し、表示するためにデータベースクエリーを使用します。また、実行前にクエリーを変更するためのビルトインフックも提供されています。

これらのフックを使ってWordPressのクエリーを変更し、WordPressの投稿、ページ、カスタム投稿タイプをセクションごとに非表示にする。

コード・スニペット・プラグインを使ってカスタムコードを追加することができます。これは最も安全な設定であり、サイトを壊すことはありません。あるいは、テーマのfunctions.phpファイルやサイト固有のプラグインにカスタムコードを追加することもできます。

非表示にしたい投稿やページのIDも必要です。WordPressで投稿IDを見つける方法のクイックチュートリアルで、この情報を取得する方法を紹介しています。

基本的には、投稿やページを編集するだけで、そのIDをブラウザーのアドレスバーに表示することができる。

Finding a post ID in the address bar

それはともかく、コードの部分に飛び込もう。

WordPressの投稿やページをホームページから非表示にする

以下のコードでは、is_home()条件分岐タグを使って、ユーザーがホームページを表示しているかどうかを調べています。もしそうなら、投稿IDをクエリーから除外します。

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

配列内のIDを、除外したい投稿やページの実際のIDに置き換えることを忘れないでください。

WordPressでこのコードを簡単かつ安全に追加するには、WPCodeのようなコードスニペットプラグインを使用することをお勧めします。

開始するには、無料のWPCodeプラグインをインストールし、有効化する必要があります。手順については、WordPressプラグインのインストール方法をご覧ください。

プラグインを有効化したら、WordPressダッシュボードからCode Snippetsメニュー項目をクリックします。そして、「新規追加」ボタンをクリックします。

Click the Add New Button to Add Your First Custom Code Snippet in WPCode

次に、「カスタムコードを追加(新規スニペット)」オプションを見つけ、その下の「スニペットを使用」ボタンをクリックします。

Add your new custom code snippet in WPCode

カスタマイザー作成」ページでは、まずスニペットのタイトルを追加します。これは、何のためのコードなのかを覚えておくのに役立つものであれば何でも構いません。

次に、上記のコードを「コードプレビュー」ボックスに貼り付け、ドロップダウンメニューからコードタイプとして「PHPスニペット」を選択します。

Paste code snippet into WPCode

その後、トグルを’Inactive’から’Active’に切り替え、’Save Snippet’ボタンをクリックする。

Activate and save your custom code snippet

次のページでは、WordPressの投稿やページを非表示にするための追加オプションをご紹介します。上記と同じ手順で、WPCodeを使ってWordPressにこれらのコード・スニペットを追加することができます。

RSSフィードからWordPressの投稿やページを非表示にする

WordPressのRSSフィードだけでなく、ホームページからもWordPressの投稿を非表示にしたい場合は、コード内でis_feed条件分岐タグを使用すればよい。

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

もしあなたが管理者としてログイン中で、WordPressのRSSフィードを閲覧しようとした場合、投稿は表示されます。他のユーザーがRSSフィードを表示しても、除外された投稿を見ることはできません。

WordPressの投稿やページをサイト内検索から非表示にする

WordPressのサイト内検索から特定の投稿を非表示にしたい場合はどうすればいいでしょうか?そのためには、is_search条件分岐タグをコードに追加するだけです。

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

これであなたのサイトにアクセスし、非表示にしたい投稿を検索することができます。これらの投稿は公開されていますが、検索結果には表示されません。

Post excluded from search results

WordPressの投稿やページをアーカイブから非表示にする

カテゴリー、タグ、日付アーカイブのようなアーカイブページから、WordPressの特定の投稿やページを非表示にするのはどうだろうか?そのためには、is_archive() 条件分岐タグを使います。

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

WordPressの投稿やページをどこからでも非表示にする

これまで、WordPressの投稿やページを特定のエリアから非表示にする方法を学んできました。では、WordPressの投稿をすべて一度に非表示にする方法はどうでしょうか?

そのためには、先に使った条件分岐タグをすべて、個別コード・スニペットにまとめればよい。

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

このコードは、指定された投稿をホームページ、RSSフィード、検索結果、アーカイブページから非表示にします。

WordPressでコンテンツの可視性をコントロールする

WordPressの投稿やページは、上で説明した2つの方法で非表示にすることができます。しかし、その前に、WordPressのコンテンツ表示コントロールオプションに関するよくある質問にもお答えします。

これらの方法は完璧にコンテンツを非表示にしているのだろうか?

いや、そんなことはない。

たとえば、投稿を非表示にする前に、検索エンジンがすでにクロールしてインデックスしている可能性があります。検索エンジンを防ぎたい場合は、GoogleからWordPressのページを非表示にする方法をご覧ください。

また、WordPressプラグインがカスタマイザークエリーを使用し、チェックをスキップして非表示にしようとしているコンテンツが表示される場合も機能しません。

より良い方法は、投稿をパスワードで保護し、パスワードを持つユーザーだけが表示できるようにすることだろう。

サイトの管理者、エディター、投稿者のみが閲覧できるプライベート投稿を作成することもできます。

これらの方法を使って、特定のユーザー向けのコンテンツを作成することはできますか?

いいえ、これらの方法では、特定のユーザーとコンテンツを効率的に共有する権限がありません。WordPressのメンバーシップ・プラグインを利用するのがよいでしょう。

MemberPressのような会員制プラグインを使えば、制限付きのコンテンツを作成・公開することができます。プレミアムコンテンツにアクセスするためのサブスクリプションプランを販売することもできます。

詳しくは、WordPressで会員制サイトを作成する方法をステップバイステップでご紹介しています。

WordPressの投稿をホームページやサイトの他のエリアから非表示にする方法について、この投稿がお役に立てたなら幸いです。WordPressサイトを完全に非公開にする方法や、WordPressユーザーに最適なVPNサービスを専門家が厳選したガイドもご覧ください。

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

34件のコメント返信を残す

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Jiří Vaněk says

    Thanks for the plugin tip. I personally use the Category Excluder plugin, but it removes the entire category from the homepage, and that doesn’t always work for me. I will try your plugin so that I don’t always have to select the whole category but only an individual article. That suits me much better.

  3. Amit says

    Hiding a post with this plugin, does it prevent search engine from crawling and indexing the post? Does it prevent the post’s google search?? Please let me know.

    • WPBeginner Support says

      No, it would not, this would be for excluding the post from your home page, not preventing it from being crawled.

      管理者

  4. Rakesh says

    Is there any way to hide specific post from only home page latest post section but not from sidebar recent post widget?

  5. Dale says

    This plugin no longer works. I have been searching for an alternative but haven’t found one yet. Would love an update to this post.

    • WPBeginner Support says

      Thank you for letting us know, we will certainly take a look at this plugin and update this article.

      管理者

        • Kelsey says

          I would just use the PHP snippet mentioned above and post it in your child theme functions.php file. That’s what I did to hide my post.

  6. Daniel says

    My only gripe is that the category post count in my category menu is incremented, even though the post can’t be shown this way. . Other than that, it is perfect.

  7. Dada says

    Hi, is google still can index the hidden post? Because i still want people can search my post on google search but not show on frontpage?

  8. campbell says

    Hi, I am wanting to keep my blog posts visible on my blog page but hidden/removed on my homepage. I downloaded the plugin and followed the instructions. When I checked “hide from front page” my blog post was removed from my blog page and not the homepage, so the opposite of what I want. How can I achieve this? Thanks!

  9. ted bergman says

    Thank you for this incredibly valuable site! When I need to know how to do something in Word Press, I first come here. You usually have the best and easiest to understand answer.

  10. Jason says

    The issue with the plugin is that if you want to have a category page show posts, then you have to leave that unchecked and “recent posts” will then pick it up and show up in all your side bars and footers :(

  11. Munna Hossain says

    This is really a great plugin. It works for me. But I don’t know why the authority doesn’t update this plugin. It still working properly.
    Thanks for your excellent artcle.

  12. coated pill says

    Is there another way to hide particular post since this is not working in my end .

    A simple tutorial might help too if I need to alter on some codes on the themes .

    Thanks

  13. Mario von Gollaz says

    The thing is that there is no real alternative to WP Hide Post. Or is there an alternative? Also WP Hide Post seems to be quite outdated (not updated since quite a while).

  14. Shakir Hassan says

    Hi,
    I’ve hide one of my blog posts from my Homepage, but still, it’s showing on Related Post section area below other blog posts.
    What should I do to get rid of it?
    WPBeginner, your answer is needed.
    Thanks.

  15. Scott says

    Another option isn’t too hide it per se but to re-schedule it to publish on a later date. I think that will effectively do the same thing…at least it did on my site just now.

    • Allie Mackin says

      I did what Scott suggested rescheduled the post for a later date. I went through the trouble of downloading and installing this app and it did not work. When I all I had to do is reschedule for a future date. Mission accomplished sans app.

  16. Dawn Cunnane says

    I really needed this to hide one post from the categories menu and it worked like a charm, thank you!

  17. Arevico says

    This is a perfect example of something I would rather have in the WordPress core than in the plugin domain. Normally, I develop my own themes and solve this by using categories. f.e how shows only most recents posts in the category ‘home’ or not in the category ‘invisible’ ,etc. This plugin help a great deal when you don’t develop your own the,e

    • Brian Jackson says

      I agree Arevico. This should definitely be part of WordPress core by now. An example just this week… I run a marketing blog, but I am doing a review on a standing desk. Since it is a little outside of my niche of readers I am publishing it without having it show up on the homepage. I want to rank for it, but don’t want to lose readers.

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。