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の検索機能を簡単に無効化する方法を紹介します。

How to disable the search feature in WordPress

なぜ、そして誰がWordPressの検索機能を無効化すべきか?

WordPressサイトには検索機能があり、訪問者がサイト内のコンテンツを探すことができます。

WordPressサイトの多くは、数ページのシンプルなビジネスサイトです。また、縦型ナビゲーションの1ページサイトも増えています。

このようなサイトはコンテンツが少ないため、検索フォームが無意味になってしまう。また、ユーザーには、検索で見つけることができる、見えない他の情報があるかもしれないという印象を与えてしまう。

検索機能を削除することで、サイトがすっきりし、ユーザーエクスペリエンスが向上します。

とはいえ、WordPressサイトから検索機能を簡単に削除する方法を見てみましょう:

方法1.プラグインを使ってWordPressの検索機能を削除する。

この方法は単純明快だ。

まず、Disable Searchプラグインをインストールして有効化する必要があります。詳しくは、WordPressプラグインのインストール方法のステップバイステップガイドをご覧ください。

Disable search plugin

有効化したプラグインはすぐに動作します。特に設定することはありません。

WordPressテーマから検索フォームを削除し、検索ウィジェットを無効化します。ユーザーが検索クエリーURLを直接入力しようとした場合、プラグインは404エラーページを返します。

404 page not found example

このプラグインはWordPress管理エリア内の検索機能には影響しません。WordPressダッシュボード内で投稿やページを検索することはできます。

方法2.WordPressの検索をコードで無効化する。

この方法では、サイトのWordPressコアファイルにカスタムコードを追加する必要があります。この方法を行ったことがない場合は、WordPressにコードスニペットを追加する方法をご覧ください。

通常、WordPressファイルを直接編集することはお勧めしません。小さなことでもサイトを壊してしまう可能性があるからです。しかし、今回はWordPressサイトにコードを追加する最も安全で簡単な方法であるWPCodeを使用します。

まず、無料のWPCodeプラグインをインストールする必要があります。詳しくは、WordPressプラグインのインストール方法のステップバイステップガイドをご覧ください。

有効化した後、管理ダッシュボードでCode Snippets “ Add Snippetを見つける必要があります。

そして、フィールドに『検索無効化』と入力し、『スニペットを使用する』をクリックすればよい。

Search in WPCode for disable search

このコード・スニペットを実行するためのすべての設定がすでに行われている画面に移動します。

必要なのは、スイッチを「有効化」に切り替え、「更新」をクリックするだけだ。

Click the Activate toggle and press Update to disable search in WordPress

このコードは検索クエリを防ぎ、フロントエンドの検索フォーム、コンテンツエディターの検索ブロック、管理バーメニューの検索ボックスを削除します。

しかし、サイトの管理ダッシュボードにアクセスできるユーザーは、投稿、ページ、コメントを検索することができます。

A before and after image for wpcode removing search feature

おまけ:WordPressでブログ機能を無効化する

検索バーの他に、WordPressのブログ機能を無効化することもできます。シンプルな1ページのサイトであれば、ブログを表示する必要はないでしょう。

例えば、オンラインショップ、オンラインポートフォリオサイト、会員制サイトなどでは、ブログ機能を使用しない場合があります。ブログ機能を使わずにWordPressサイトを構築することは可能ですが、管理エリア内では表示されたままになります。

必要なのはDisable Blogプラグインをダウンロードするだけで、ブログ関連の設定や管理ページとともに投稿タイプを非表示にすることができる。

有効化すると、ブログは自動的に管理サイドバーの左メニューから「投稿」設定を削除します。詳しくは、WordPressでブログの機能を簡単に無効化する方法のチュートリアルをご覧ください。

disable blog example

WordPressの検索機能を簡単に無効化する方法について、この投稿がお役に立てれば幸いです。WordPress サイトに Google 検索を追加する方法についての初心者向けガイドや、WordPress のエキスパートが選ぶ最高の検索プラグインもご覧ください。

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

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

  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. Steven says

    Line 11 of method 2 was not hiding the search form for my installation, but makes the default form appear, which is loaded / generated by general-template.php’s function get_search_form (at least WordPress 5.4.2).

    The function applies the filter get_search_form. In case the filter returns null (null === $result, line 299), the previously loaded or generated default form will be shown or returned.

    To hide the form, I had to change line 11 needs to return an empty string:

    add_filter(‘get_search_form’, function ($a) { return ”; });

  3. lee maupa says

    i have the same problem in that im failing to access the customization nav and iv tried to make changes in the code but not getting any joy. i have tried to install the plugin but still the search still appears. please some one help how to resolve this issue.
    which folder/file do i get the header menus maybe i can remove it from there, please assist

    • WPBeginner Support says

      That can vary from theme to theme where the file is after you to into your wp-content/themes/theme name file. Some themes have a header.php while others have the code in another location. If you reach out to your theme’s support they should be able to assist.

      管理者

  4. Sherell says

    Thank you for posting this! I was filling my site with all kinds of crazy codes I was finding on the internet in hope of getting rid of that doggone search box! Now everything is good!

  5. Jeff Cohan says

    Thanks for this. Very useful.

    A few comments:

    1. Method 2 (manual) works for me (i.e., removing search box) on a child theme of twentyeleven, but only for a search *widget* added to a widget area. It leaves the search box that is hard-coded (using get_search_form()) into header.php. I know I can override the parent theme’s header.php by cloning/editing it, but I’l like to know how to disable that search form programatically.

    2. I cannot get Method 2 to work on a Genesis theme. I wonder if you or anyone has some insights here.

    3. A little thing: the method 2 script needs a closing brace on line 14.

  6. Toddp says

    Ok it removed the search box but left the search title that we must now figure out how to remove.
    DO you have an plugin for that?
    Seems to me you would have an option like this already installed in the site builder.

  7. Samantha says

    Sometimes you can disable the search feature for example, on an one page site that does not really need a search feature.

  8. Tati says

    Thanks for the article. What I need to know is: can I disable only some terms of the search and keep the search function working? I want to exclude things like /?s=d, download, thank, success, congratultions… terms that hackers use to find specific pages inside our sites.

    Can someone help me with this? TIA

  9. Silvana Donato says

    Thank you very much.
    I have just been hacked in the database of one of my websites and I have removed all the possible gates to these terrible annoying people, who have nothing to do in life but distroying other people work.
    So I removed the search forms but i did not know how to remove the query string.

  10. Gary C says

    Another reason for disabling the search box that comes with WordPress is to replace with a different search box, such as Google Custom Search.

    Google Custom Search allows you to monetize your search pages provides you have an Adsense account.

  11. Steven Bradley says

    I’m having a hard time understanding the usefulness of this code. If search is unnecessary wouldn’t it make more sense to not include the search form? If you leave a search form on a page and then don’t let someone use that search form isn’t that very poor usability?

    Am I missing something?

    • Editorial Staff says

      You can remove the search form in the design, but the functionality stays. Anyone who knows it is WordPress can simply add a /?s=keyword and search the site. But by removing the form and adding this code will take care of that problem. There will be time when you have a client that only wants pages or posts to be shown if the URL is available. This function will come handy in that sense.

      管理者

    • Toddp says

      Yes it makes more sense to leave out search and other widgets and allow the customer to add them if they want them and not put them by default.

  12. Marc T says

    Hmmmm…. can’t imaging Search not being important for a CMS. Isn’t the fact that WordPress has such a fine Search feature a huge advantage when using it as a CMS? I can imaging Search only being not important on a small portfolio site say limited to 5 pages or so.

返信を残す

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