In some cases, the vB5 search results may not provide you what you're searching for in a forum. You could replace the default vB5 Search box with the Google Search box or add a Google search result link (and other search engines) together with the vB5 search results. These search engine links will redirect the user to their search results for your site.
If you are more interested in the latter, then continue reading.
Before giving you the code to accomplish what is shown in the above screenshot, let me give you first the limitations/disadvantages of doing this modification:
vB5 (Self-Hosted):
vBCloud:
vBCloud supports Template Hooks but unfortunately, there is no suitable template hook locations on the Search Result page. Thus, we'll just do the old-fashioned workaround for vBCloud by creating a hidden Static HTML module.
Demo:
Try searching on this site or clicking this search result:
https://vbmods.rocks/search?q=IP&sea...%3A%22IP%22%7D
Enjoy!
If you are more interested in the latter, then continue reading.
Before giving you the code to accomplish what is shown in the above screenshot, let me give you first the limitations/disadvantages of doing this modification:
- Your site must be public as search engines cannot index private pages.
- Your site will lose branding to search engines as users are taken out of your site and redirected to search engine search results page.
- Recent content from your forum may not be instantly available until search engines index your site.
- This mod requires editing the Search Results template which means the changes may cause template conflicts during upgrades.
- Since this requires template editing, this is not for vBCloud although there is another solution to implement it that will work on vBCloud.
vB5 (Self-Hosted):
- Logon to AdminCP.
- Go to Styles → Search in Templates
- Choose the target style/theme in the "Search in Style" dropdown.
- In the "Search for Text" field, type widget_search_results.
- Select "Yes" in the "Search Titles Only" radio button.
- Click Find button.
- In the search results, double-click the template to edit it or select it then click Customize button.
- Find the following code (Click the Template input box and press Ctrl+F or Command+F)
Code:<vb:if condition="!empty($nodes['ignored_keywords'])">
- Find its closing </vb:if> tag
- Below that code, insert the following code:
Code:<vb:if condition="!empty($searchJSONParam['keywords'])"> <p class="alternative-search-engine-search h-margin-top-l"> Can't find what you're looking for? See <a href="https://www.google.com/search?q={vb:urlencode {vb:raw searchJSONParam.keywords}}+site%3A{vb:urlencode {vb:raw baseurl}}" target="_blank"><strong>Google</strong></a> search results for '{vb:raw searchJSONStructure.keywords}'. </p> </vb:if>
DuckDuckGo:
HTML Code:<a href="https://duckduckgo.com/?q={vb:urlencode {vb:raw searchJSONParam.keywords}}+site%3A{vb:urlencode {vb:raw baseurl}}" target="_blank"><strong>DuckDuckGo</strong></a>
HTML Code:<a href="https://www.bing.com/search?q={vb:urlencode {vb:raw searchJSONParam.keywords}}%20site%3A{vb:urlencode {vb:raw baseurl}}" target="_blank"><strong>Bing</strong></a>
HTML Code:<a href="https://search.yahoo.com/search?p={vb:urlencode {vb:raw searchJSONParam.keywords}}+site%3A{vb:urlencode {vb:raw baseurl}}" target="_blank"><strong>Yahoo</strong></a>
HTML Code:<a href="https://yandex.com/search/?text={vb:urlencode {vb:raw searchJSONParam.keywords}}+site%3A{vb:urlencode {vb:raw baseurl}}" target="_blank"><strong>Yandex</strong></a>
Code:<vb:if condition="!empty($searchJSONStructure['keywords'])"> <p class="alternative-search-engine-search h-margin-top-l"> Can't find what you're looking for? See <a href="https://www.google.com/search?q={vb:urlencode {vb:raw searchJSONStructure.keywords}}+site%3A{vb:urlencode {vb:raw baseurl}}" target="_blank"><strong>Google</strong></a> or <a href="https://duckduckgo.com/?q={vb:urlencode {vb:raw searchJSONStructure.keywords}}+site%3A{vb:urlencode {vb:raw baseurl}}" target="_blank"><strong>DuckDuckGo</strong></a> search results for '{vb:raw searchJSONStructure.keywords}'. </p> </vb:if>
- Find the following code:
-
Code:
<vb:if condition="isset($nodes['errors'])">
- Below that code, insert the same code used in Step 10.
- Click Save button.
- Repeat Steps 2-14 for other active styles/themes on your forum (if any).
vBCloud:
vBCloud supports Template Hooks but unfortunately, there is no suitable template hook locations on the Search Result page. Thus, we'll just do the old-fashioned workaround for vBCloud by creating a hidden Static HTML module.
- Perform a search on your site. Any keyword is fine. We just want to go to the Search Result page.
- Enable Sitebuilder by toggling Edit Site slider to ON.
- Click Edit Page.
- Drag and drop a Static HTML module onto the page below the Search Results module.
- Edit the Static HTML Module by clicking the Pencil icon.
- Enter the following configuration:
Title: Search Engine Links Script
Show module at these screen sizes: (Uncheck ALL checkboxes)
Module HTML:
- Copy the code below.
- Paste the code in a text editor.
- Modify the searchEngines list in the code to remove search engines you don't want to display.
- Copy the updated code and paste it into the Module HTML textbox.
Code:<script> (function() { // Remove other search engines as desired and // make sure there's no trailing comma at the last search engine in the list var searchEngines = ['Google', 'DuckDuckGo', 'Bing', 'Yahoo', 'Yandex']; // DO NOT MODIFY ANYTHING BELOW UNLESS YOU KNOW WHAT YOU'RE DOING!!! var searchInsertLocation = document.querySelector('.search-result-header .search-controls, .search-results-widget .widget-content .error'); if (!searchInsertLocation) { return; } var keywords; var keywordsInput = document.querySelector('.js-search-keywords'); if (!keywordsInput || !keywordsInput.value) { var qs = vBulletin.parseQueryString(location.href); if (qs.searchJSON) { try { var json = JSON.parse(qs.searchJSON); keywords = json.keywords; } catch (e) { return; } } else { return; } } else { keywords = keywordsInput.value; } var encodedKeywords = encodeURIComponent(keywords); var siteFilter = encodeURIComponent(' site:' + pageData.baseurl); var p = document.createElement('p'); p.className = 'alternative-search-engine-search h-margin-top-l'; var linkList = searchEngines.map(function(s) { var url = ''; switch (s) { case 'Google': url = 'https://www.google.com/search?q=' + encodedKeywords + siteFilter; break; case 'DuckDuckGo': url = 'https://duckduckgo.com/?q=' + encodedKeywords + siteFilter; break; case 'Bing': url = 'https://www.bing.com/search?q=' + encodedKeywords + siteFilter; break; case 'Yahoo': url = 'https://search.yahoo.com/search?p=' + encodedKeywords + siteFilter; break; case 'Yandex': url = 'https://yandex.com/search/?text=' + encodedKeywords + siteFilter; break; default: break; } return url ? '<a href="' + url + '" target="_blank"><strong>' + s + '</strong></a>' : ''; }); var links = linkList.join(', '); var lastCommaIndex = links.lastIndexOf(','); if (lastCommaIndex !== -1) { links = links.substring(0, lastCommaIndex) + ' or ' + links.substring(lastCommaIndex + 2); } p.innerHTML = "Can't find what you're looking for? See " + links + " search results for \"" + keywords + "\"."; searchInsertLocation.parentElement.insertBefore(p, searchInsertLocation); })(); </script>
7. Click Save button.
8. Click Save Page button.
9. Click OK button.
10. Click Save Page button.
Demo:
Try searching on this site or clicking this search result:
https://vbmods.rocks/search?q=IP&sea...%3A%22IP%22%7D
Enjoy!
Comment