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

Så här inaktiverar du funktionen Search i WordPress (enkelt och smidigt)

Vill du inaktivera funktionen search i WordPress?

Ibland kanske din site inte behöver WordPress utvalda funktion för search, eller så kan sökformuläret i ditt theme störa användarens upplevelse.

I den här artikeln visar vi dig hur du enkelt inaktiverar funktionen search i WordPress.

How to disable the search feature in WordPress

Varför och vem ska inaktivera funktionen Search i WordPress?

WordPress-webbplatser har en search-funktion som låter visitors söka efter content på din website.

Många WordPress-webbplatser är enkla företagswebbplatser med några pages. Det finns också en växande trend av webbplatser med en sida med vertikal navigation.

Dessa websites har inte mycket content, vilket gör ett search-formulär meningslöst. Det ger också användarna intrycket att det kan finnas annan information som de inte kan se och som de kan hitta genom en search.

Om du tar bort funktionen search kommer du att städa upp din website och ge användarna en bättre upplevelse.

Med detta sagt, låt oss ta en titt på hur du enkelt kan ta bort funktionen search från din WordPress site:

Metod 1. Ta bort utvald search-funktion i WordPress med hjälp av ett plugin

Denna metod är enkel och okomplicerad.

Först måste du installera och aktivera pluginet Disable Search. För mer detaljer, se vår Step-by-Step guide om hur du installerar ett WordPress plugin.

Disable search plugin

Efter aktivering fungerar pluginet omedelbart. Det finns inga Settings som du måste konfigurera.

Det kommer att remove search formulär från din WordPress tema och inaktivera sök widget. Om en användare direkt försöker enter en URL för en sökning, kommer pluginet att returnera en 404 error page.

404 page not found example

Obs/observera att detta plugin inte påverkar search-funktionen i WordPress admin area. Du kan fortfarande söka efter post och pages i din WordPress dashpanel.

Metod 2. Inaktivera Search i WordPress med kod

Den här metoden kräver att du addar custom code till din sites WordPress core-filer. Om du inte har gjort det tidigare kan du ta en titt på vår guide om hur du lägger till code snippets i WordPress.

Normalt rekommenderar vi inte att du direkt editerar dina WordPress-filer, eftersom även små saker kan förstöra din site. Vi kommer dock att använda WPCode, som är det säkraste och enklaste sättet att add to kod till din WordPress site.

Först måste du installera det gratis pluginet WPCode. För mer detaljer, se vår Step-by-Step guide om hur du installerar ett WordPress plugin.

Efter aktivering måste du hitta Code Snippets ” Add Snippet i din adminpanel.

Sedan behöver du bara skriva ”inaktivera search” i fältet och sedan klicka på ”Använd snippet”.

Search in WPCode for disable search

Du kommer nu till en vy där alla Settings för att runna detta code snippet redan har konfigurerats.

Allt du behöver göra är att toggle omkopplaren till ”Active” och click ”Update”.

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

Den här koden förhindrar sökfrågor och tar bort sökformulär från front-end, sökblocket från content editor och sökboxen i admin bar menu.

Användare som har tillgång till webbplatsens adminpanel kommer dock fortfarande att kunna söka igenom posts, pages och comments därifrån.

A before and after image for wpcode removing search feature

Bonus: Inaktivera funktioner för bloggar i WordPress

Förutom sökfältet kanske du också vill inaktivera funktionerna för blogg i WordPress. Om du har en enkel website med en page behöver du inte visa upp en blogg.

Till exempel kanske många onlinebutiker, webbplatser med portföljer online eller membership sites ej har användning för bloggar. Du kan bygga din website i WordPress utan att använda funktionerna för blogg, men de kommer ändå att vara synliga i admin area.

Allt du behöver göra är att downloada pluginet Disable Blog, som kommer att dölja post typen tillsammans med alla bloggrelaterade inställningar och admin pages.

Vid aktivering tar bloggen automatiskt bort inställningarna för ”Post” från vänstermenyn i admin sidebar. För mer detaljer, kontrollera vår tutorial om hur du enkelt inaktiverar funktioner för bloggar i WordPress.

disable blog example

Vi hoppas att den här artikeln hjälpte dig att lära dig hur du enkelt inaktiverar funktionen search i WordPress. Du kanske också vill se vår guide för nybörjare om hur du lägger till Google-sökning på en WordPress-webbplats och vårt expertval av de bästa tillägg för search för 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.

Avslöjande: Vårt innehåll stöds av våra läsare. Det innebär att om du klickar på några av våra länkar, kan vi tjäna en provision. Se hur WPBeginner finansieras, varför det är viktigt, och hur du kan stödja oss. Här är vår editoriala process.

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.

Den ultimata WordPress-verktygslådan

Få GRATIS tillgång till vår verktygslåda - en samling WordPress-relaterade produkter och resurser som varje professionell användare bör ha!

Reader Interactions

22 kommentarerLämna ett svar

  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.

      Administratör

  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.

    • WPBeginner Support says

      Thank you for letting us know about the closing brace, we’ll be sure to update it :)

      Administratör

  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.

      Administratör

    • 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.

Lämna ett svar

Tack för att du väljer att lämna en kommentar. Tänk på att alla kommentarer modereras enligt våra policy för kommentarer, och din e-postadress kommer INTE att publiceras. Vänligen använd INTE nyckelord i namnfältet. Låt oss ha en personlig och meningsfull konversation.