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 lägger du till Google Search på en site i WordPress (det enkla sättet)

Som standard levereras WordPress med en inbyggd sökfunktion, men den är inte särskilt bra. Du kan dock enkelt ändra på det genom att lägga till Google Search i stället för att ge mer relevanta och korrekta resultat.

Detta kommer att förbättra användarupplevelsen på din blogg och göra det lättare för besökare att hitta det innehåll de letar efter. Vi har märkt att detta leder till ökat engagemang och en större chans att konvertera tillfälliga besökare till lojala läsare eller klienter.

I den här artikeln visar vi dig hur du enkelt addar Google Search till en site i WordPress.

Add Google Search in a WordPress Site

Varför ska du använda Google Search i WordPress?

Den utvalda funktionen för search i WordPress är inte särskilt användbar och Misslyckas ofta med att hitta relevanta resultat på användarnas sökningar. Detta tvingar många webbplatsägare att leta efter alternativ.

Du kan använda ett populärt tillägg för search i WordPress. Problemet är dock att du fortfarande måste hantera det pluginet, och det kommer att påverka dina server-resurser.

Å andra sidan kan du använda Googles tillförlitliga och kraftfulla utvalda search-funktion istället. Den är gratis, allow you att limit the search to your sites only, och kan runas från din WordPress site.

Dessutom är Google search snabb, användarna litar redan på varumärket och du behöver ej underhålla eller updating det. You can even allow users to search external websites on Google if needed.

Med detta sagt, låt oss se hur du enkelt kan add to en Google site search till din WordPress webbplats.

Så här addar du Google Search till en site i WordPress

Du kan enkelt add to Google Search till din WordPress site genom att besöka Google Programmable Search Engine website.

Klicka sedan på knappen ”Kom igång”.

Click the get started button on the Programmable Search Engine page

Du kommer då till sidan ”Create a new search engine”, där du måste add to ett namn på det sökformulär som du nu ska skapa.

Därefter väljer du alternativet ”Search specific sites or pages” i ”What to search?” section och add to your WordPress site’s URL.

Nu kommer Googe Site Search endast att indexera det content som finns tillgängligt på din website. Men om du vill att Google ska visa sökresultat från andra websites också, kan du välja alternativet ”Search the entire web”.

Add website URL to create Google Site search

Därefter rullar du ner och togglar på alternativet ”Image Search” för att allow your Google Search form to index images on your website. Vi rekommenderar det här alternativet om du säljer foton online, har en website för fotografier eller runar en blogg om resor.

Efter det kan du också toggle på ”Safe Search” -knappen så att användarna inte visas olämpliga resultat för sina sökningar.

När du är klar klickar du på knappen ”Create”.

Click create to generate a google search engine ID

Google kommer nu att generera din ID:n för search engine åt dig.

Därefter kopierar du bara koden och klistrar in den i en Notepad-app eller vanlig textredigerare.

Copy the Google Search Engine ID from the website

Nu måste du besöka din WordPress dashboard och editera dina theme-filer för att add the search till din sites <body>. Detta kan dock vara riskabelt, och minsta error kan förstöra din website.

Det är därför vi rekommenderar att du använder WPCode istället. Det är det bästa WordPress code snippets plugin på marknaden som gör det säkert och enkelt att lägga till custom code.

Först måste du installera och aktivera pluginet WPCode. Detaljerade instruktioner finns i vår guide för nybörjare om hur man installerar ett plugin för WordPress.

Note: WPCode har en gratis plan som du kan använda för denna tutorial. Men om du uppgraderar till Pro-versionen får du tillgång till fler funktioner som smart villkorlig logik, ett molnbibliotek med code snippets och mer.

Efter aktivering, besök Code Snippets ” + Add Snippet page från WordPress admin sidebar. Här klickar du på knappen ”Use Snippet” under alternativet ”Add Your Custom Code (New Snippet)”.

Add new snippet

Detta tar dig till sidan ”Create Custom Snippet”, där du kan skriva in vilket namn du gillar för snippet. Välj sedan ”Universal Snippet” som code type i dropdown-menyn till höger.

När du har gjort det klistrar du bara in Googles ID:n för Search Engine i boxen ”Code Preview”.

Paste the Google Search Engine ID into WPCode preview box

Bläddra sedan ner till avsnittet ”Insertion” och välj läget ”Auto Insert”. Efter aktivering kommer Google Search-formuläret automatiskt att läggas till på din webbplats.

Efter det kan du förstora dropdown-menyn ”Location” för att välja var du vill visa din search box.

Om du t.ex. vill visa sökformuläret högst upp på alla dina pages och posts kan du välja alternativet ”Insert Before Post”.

Choose location and insertion for the search engine ID

Därefter rullar du tillbaka högst upp och togglar omkopplaren ”Inaktiverad” till ”Aktiv”.

Slutligen klickar du på knappen ”Save Snippet” för att lagra dina Settings.

Save Google Search Engine ID snippet

Du har utan problem lagt till ett formulär för Google Site search manuellt.

Du kan nu besöka din WordPress blogg för att se den i action.

Google Search preview

Alternativ: Använd SearchWP för att skapa ett fantastiskt sökformulär

Om du tycker att det är svårt att lägga till Google Site Search på din webbplats eller om du letar efter ett alternativ kan du använda SearchWP för intern sökning.

Det är det bästa WordPress search plugin på marknaden som automatiskt ersätter standard sökformuläret och tillåter användare att hitta allt de behöver på din site.

The SearchWP search plugin for WordPress

SearchWP används av över 50.000 webbplatser och låter dig skapa en anpassad relevansskala för att justera sökalgoritmen.

Du kan också göra alla delar av din webbplats sökbara, inklusive PDF-filer, anpassade inläggstyper, media, kommentarer, anpassade fält, WooCommerce-produkter och mycket mer.

Om du har en flerspråkig site kan du också skapa en flerspråkig search med detta plugin.

Configure SearchWP engine settings

Du måste dock komma ihåg att, till skillnad från Google Search, kan plugin bara indexera och visa resultat för content som är available på your website.

För mer details, you can see our tutorial on how to improve WordPress search with SearchWP.

Video Tutorial

Är du inte så förtjust i att läsa instruktioner? Det är inget problem! Vi har skapat en praktisk videoguide som guidar dig genom processen:

Subscribe to WPBeginner

Vi hoppas att den här artikeln hjälpte dig att lära dig hur du enkelt lägger till Google Sök på en WordPress-webbplats. Du kanske också vill läsa vår nybörjarguide om hur du lägger till röstsökfunktion på din WordPress-webbplats och vår handledning om hur du gör blogginläggskommentarer sökbara i 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

83 kommentarerLämna ett svar

  1. Ruhul Mashbu

    When I insert the google engine id the plugin automatically creates a page where the search result will be displayed. But what I need is to change the link of the page where the search result will be displayed. How can I do that?

  2. Yohan Perera

    I am using the WP Google Search Plugin. I was so frustrated because I couldn’t get the search icon show. Your tip on customizing the search box through the dashboard in Google Custom Search solved the problem.

  3. Graham FB

    Cool artricle but what I wanted to have a the custom search box in the centre of a blank page as if it was a google search page. I found the plugin Blank Slate which gives the blank page just not sure how to either center and limit the width of the search box either by code or shortcode any ideas ??

  4. Saurabh Saneja

    Thanks wpbeginner your articles have always helped me a lot. I wanted to do it manually because that way wherever I have search form it’ll be replace by custom google search and your article did work for me as always :)

    When i tried it first it didn’t work because I registered website as http(s) or didn’t enclose the code within a div so it really gave e a hard time. Anyway i am all thanks for your help!!

    Thanks again :)

  5. Dwi Okta N

    oh.. use the plugin. Iam just know it.

    thx for info..

  6. Craig

    I figured it out. My Search Result page wasn’t published yet.

  7. Craig

    It works exactly how I want it to, searching 2 different web sites, as long as I am logged into WP Admin. Once I’m no longer logged in to the WP Admin I get

    Not Found
    Apologies, but the page you requested could not be found. Perhaps searching will help.

    What step did I miss?

    • Dibyandu Pal

      I don’t have much idea about web designing and further customizing. I am learning wordpress blogging from last 5 months, and I think it may be due to a problem while publishing your search result page. There is a visibility option in edit page mode. If that page is private or password protected, this problem you said may arise. If it is done so, make it public..

  8. Ankit Yadav

    Works great.

  9. Koala

    Thank you very helpful! :)

  10. Stacey

    Can the Google Search be used on Internal company websites?
    If so how is this accomplished?

  11. Shri

    Plugin method works well for me. But I am trying to replace theme’s native menu bar search functionality with CSE. Its wordpress native search only. So manual editing searchform.php method should work for me.
    But after editing searchform.php my search widget vanishes from sidebar. I am using Colormag theme by themegrill.
    Looking out for a help.

    I am also keen to see mentioned in above comment but this site is offline now. I tried to fetch it from wayback machine but couldn’t found in its past impressions.

    • Dana

      The same thing happens to me when I paste that code into searchform.php. Not sure this is proper as searchform.php by default is an HTML form. The code copied from Custom Google Search is a JavaScript tag…. should this even work??

  12. Waleed Younas

    Really Helpful topic as always.

    I am using a Plugin in my Site. How can I exclude ads from Search Results

  13. Jackson

    Hi Wpbeginner,

    This worked like charm! The manual method is just as awesome as you wrote. Google custom search now showing on my site!

    Thank you so much.

  14. Claire Brotherton

    Can you only implement custom search when the site is live and indexed by Google? If it’s hidden or password protected, can it be added then?

      • Claire Brotherton

        That’s what I thought. Thanks for your reply! :)

  15. Susanna

    I am trying to add Google Search with the Plugin to my website. I got as far as the step where I am supposed to paste the search engine ID into the WP Google Search’s settings page. My settings page does not seem to have any place where I can do this. Can you tell me where the ID should be pasted and what it is called?

    Thanks.

  16. fdecicco

    the manual way of doing this is poorly described and a total waste of time. If you gonna do something do it right ir dont do it at all.

    • WPBeginner Support

      If you are having difficulty using the manual method, then please try the first method. It is easier to add Google Search with the help of a plugin. If you need to do it manually, then please let us know which part isn’t clear and we will try to explain it here.

      Administratör

      • saajan bedi

        Manually Adding Google Search doesn’t work (I’m using colormag theme), U need to Update the article

  17. phil davis

    By using this search plug-in will I be able to see a report on what words were typed in the box to search for?

    I want to know what people are searching for, so I can create content based on their search.

  18. Ameer Shaik

    I have updated through plugin method. Only search button is not displayed properly. Please suggest(The text ”Search” is moved down, only top portion is visible). Pl suggest

  19. Bruno Bezerra

    Beautiful tool! Having a search field is more than necessary.

  20. Jennifer

    Another awesome tutorial – I didn’t even know it was possible to use Google Search like this! I’ve now got this running on my website, thanks so much!

  21. Imran Khan

    Nice post, very helpful as well as easily understandable. I have also created my custom search bar by following your steps. Thanks for sharing this great post with us.

  22. Angelo

    Hi!

    Do we have to choose among among the 5 font options available or we can import a font we like better?

  23. wiziwiz

    how to set it so the results when clicked open in the content area?

    • wiziwiz

      otherwise thanks and awesome post

  24. Eric Kazda

    Can somebody tell me why this is a more beneficial search than using the standard WordPress search form? Are there SEO implications? I’m just not sure why anyone would use this over the standard search.

    • Adam Connell

      I generally find that whenever I search a website for a topic, and it’s using WordPress default search – I’ll get VERY poor results.

      They’ll lack relevance.

      By using Google’s custom search, you won’t get any SEO benefits but your readers will find it easier to get what they’re looking for.

  25. Priti

    In ”Search by Google” how to we specify the our google search id ? In widget don’t we have to keep the google search engine id?

  26. Carol Long

    Hi – can you tel me please how to remove this? I have just seen it appear on all my pages and I don’t want it at all!

    Many thanks

  27. Richard Bishop

    Hello, and thank you for creating this post and video. I really found it to be helpful in terms of providing better search results for my site WarCraft Press.

    I would however say that you should have pointed out at the beginning of the lesson there are 2 ways to accomplish this task. I did it once with out the plugin then later realized there was a plugin for it.

    That said thanks again for a great lesson and I certainly look forward to future lessons!

    Kombear
    WarCraft Press

  28. cowboy Mike

    Howdy,
    I have seen you recommend editing wp files and wp theme template files like you have in this article for the searchform.php file.

    My concern is when there is a theme update or wordpress update wouldnt the changes to the searchform.php suggested here be lost after for example a theme update?

    Happy trails, Mike

  29. Shahadat Hossain

    can i use google custom search box and wp normal box all together in my site. or i will have to use only one search box between two of this search box

    • WPBeginner Support

      You can use both if you want. This will be a bit confusing for users though.

      Administratör

  30. Nasser

    How to make a search bar that join to google? Not just a small windows as Custom google search. Exactly work as google search.
    Thanks.

  31. Caroline

    The search results opens up in a new window, how can I open them in my search.php?

  32. Ramesh Tatipigari

    Hi ,

    I want to add google search bar to every post of my wordpress site or i want to add google search bar to below main menu could you please help me regarding this.

  33. boooka

    my search terms cannot be seen. what happened

  34. Day Milovich

    i prefer to change wordpress search completely with google custom search engine to get better traffic from google.

  35. Rahul Yadav

    Hi, I would like to know how to use google custom search in menus like you use……..

  36. Vipul Behl

    Thanks for the tutorial i was able to create a search for my blog.

  37. Javed Ahmadzai

    Well, I have done the same procedure. my theme does not contain searchform.php i created it but it contain searchresults.php i think its theme’s search. but after creating the searchform.php and pasting the code there. another search widget not appeared. Only sahifa search which is theme’s so please can you tell me what the problem. :(

  38. Raghu

    Hi, I would like to know if I can use google custom search for my intranet portal. I have setup wikipedia for internal purpose and I would like to integrate google custom search for this, however I am not getting result when I integrate.
    So the question is: Is google custom search meant only for public websites?

  39. Rajnish

    Really helpful post. I integrated search box for my Website successfully. Thanks WPBeginner :)

  40. Chris

    Hi, I went through these steps exactly for my Wordpress site, but the search box doesn’t appear anywhere. There are no .js errors in the console. I put a border around the containing div and the border appears, but there’s nothing inside it. I pasted the code I generated from Google inside searchform.php. As a test I also tried pasting the google code on a test page, but still no luck.

    Any ideas on troubleshooting?

  41. Deepak Singh

    Can you please guide me how we cana dd Custom Search in genesis child theme. I tried many tutorials but none of them work.

    • WPBeginner Support

      Genesis is a theme framework, you should check out their documentation or use support forums.

      Administratör

  42. Joy Baker

    Oops. Guess the form requires pre tags or something.

  43. Joy Baker

    Forgive my newbie status, but when pasting the code into the search.php of my theme’s search page, do I replace the code in the page with Google’s code? I am an idiot when it comes to php code. I know what it looks like, what the opening/closing tags look like, but I have no idea what you mean when you say paste the code in the page.

    Where? Replace it all or between the opening/closing tags or… ???

    Current code looks like this:


    So, do I replace the entire code in the page with the custom Google Search I’ve created?
    Google code:


    Thanks for any help you can give.

  44. David Trees

    Thanks for a very well written article. It is easy to read and follow,even for a complete newbie.

    The only thing I don’t get, is how to do this;

    ”If your theme does not have a searchform.php file, then you need to create one using a text editor like Notepad and upload it to your theme directory using FTP client”

    Remembering I am a newby. I did instal my WP site to my shared hosting by following clear instructions, using FTP. So I guess I am saying how does one create the searchform.php file?

    Thanks again.

    • WPBeginner Support

      Open your FTP client and connect to your shared hosting site. Navigate to /wp-content/themes/ directory. Click on the theme you are using. For example if you are using twentytwelve theme you will see a directory twentytwelve there, open it. Once you have opened your theme directory in your FTP client, right click and select ’Create new file’. A new dialog box will appear enter searchform.php as the file name. That’s all you have created searchform.php file.

      You can also create this file on your computer by opening a plain text editor like notepad and save file as searchform.php, after creating the file you can upload it to your theme directory using an FTP client.

      You can edit this file from inside your WordPress Admin area. Go to Appearance » Editor and click on searchform.php file from the list of files on the right.

      Administratör

      • Patricia

        I tried to do just that but something else happened. The search box disappeared and was replaced by an ad. The widgets below the search widget area in my primary sidebar also disappeared. I’ll figure this out soon. It’s a pretty nifty feature.

  45. Abhisek

    This is a very simple and easy to digest. But, if anyone want to use his/her theme’s default search bar and display the search results then how will he integrate google cse with his theme’s search, I found a great and simple method, it just requires editing your search.php file of your theme, just replace the php statement that is responsible for showing the search results. Feel free to read the full post at my blog :

  46. George Byers

    Thats great and all… but my search field is on the menu bar.

    • WPBeginner Support

      Look in the code if it is using the function <?php get_search_form(); ?> then this method should work for you.

      Administratör

  47. John

    Thanks so much! You always have the best tutorials.

    John

  48. Huzaima Khan

    Really helpful post. I integrated search box for my blog successfully. Thanks WPBeginner :)

  49. amrilio

    Can you tell me, how to make share & comment button like your blog? please

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.