• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

How can I add custom search page not found in WordPress

ImCesar

Member
May 29, 2020
33
27
18
India
shrinkme.ml
When i search a qurey that doesn't exist on my site it will show a white page without any kind of statement like ''The post you are looking for not exist in this site". How can i add this ?
 
When i search a qurey that doesn't exist on my site it will show a white page without any kind of statement like ''The post you are looking for not exist in this site". How can i add this ?

You can achieve this in two ways.

1. Edit the "search.php" in your WP installation. I prefer this because it offers more customization option, but be careful when editing WP files. It requires some background in HTML and a little PHP. it's easy peasy once you get the hang of it.

2. Get a plugin that will do this for you (safe), but your options are limited to what the plugin can offer. Plus extra load to your website, and some of these plugins still use old jQuery versions(render blocking) = sloooow
 
You can achieve this in two ways.

1. Edit the "search.php" in your WP installation. I prefer this because it offers more customization option, but be careful when editing WP files. It requires some background in HTML and a little PHP. it's easy peasy once you get the hang of it.

2. Get a plugin that will do this for you (safe), but your options are limited to what the plugin can offer. Plus extra load to your website, and some of these plugins still use old jQuery versions(render blocking) = sloooow

I know Html i can edit it but i can't understand the contains of search.php file. What should i do ?
 
In any great premium wordpress theme there are the good redirecting to 404 page fully customizable.
 
When i search a qurey that doesn't exist on my site it will show a white page without any kind of statement like ''The post you are looking for not exist in this site". How can i add this ?
use elementor template.
 
Using plugin can slow down site i want use alternate method



I just found it on the net, so this is not mine. Hopefully can help your problem. But read carefully till the end, it's recommend to your site speed.

A Better Way to Add Google Custom Search to WordPress/PHP Site
By Brij Mohan

It is common to use Google Custom Search for WordPress Site because of its speed, search algorithm, trustability, security, no need of server resources and database load for indexing..etc. This post will explain how to add Google Custom Search in your WordPress or PHP site without any plugin.


Get CSE Code:
Login Google Custom Search and add a new search engine.
Left side, select your search engine and click on “Look and feel” option
Google Custom Search Engine

Select “Result Only” layout and click “Save and Get Code“.Copy it, the code will be like below:
?
<script>
(function() {
var cx = 'partner-pub-xxxxxxxxxxxxxxxx:xxxxxx-xxxx';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:searchresults-only></gcse:searchresults-only>
Why Results Only:
I selected “Result Only” layout means not selected to use Custom Search Box because:
1. Google Custom Search box loads background image as watermark. We can remove it with CSS or javascript tweaks but it is against the terms of service.
2. If we use it then need to add javascript code which will be on all pages (because search box will be present in all pages). Google PageSpeed throws following error:
Eliminate render-blocking JavaScript and CSS in above-the-fold content

http://www.google.com/cse/api/branding.css

It affects PageSpeed score and page load time for all pages.
Search Results:
On WordPress or PHP website, create a page (say ) and paste the CSE code where you want to show search results.
Setup Search Box:
As we are using result only from Google CSE script, we will add our own textbox for searching. Put following code in header or sidebar where you want to display search box:
?
<div class="searchbox">
<form action="https://techbrij.com/search-result" id="cse-search-box" method="get">
<div>
<?php if (isset($_GET['q'])) { ?>
<input type="text" name="q" size="35" id="txtGoogleSearch" placeholder="Search Here" value='<?php echo $_GET['q'] ?>' />
<?php } else {?>
<input type="text" name="q" size="35" id="txtGoogleSearch" placeholder="Search Here" />
<?php } ?>
</div>
</form>
</div>
You can easily set look and feel and customize it as your choice. That’s it. Now search it and test it.
Google Custom Search Engine

How It Works:
You can enter keyword to search and on enter, the url becomes
search-result?q={search keyword}
Google CSE script fetches search keyword from querystring and displays search results.
Conclusion:
In this post, we added Google custom search to WordPress/PHP site considering Google PageSpeed and site performance.
Enjoy Google Custom Search !!
 
I know Html I can edit it but i can't understand the contains of search.php file. What should i do ?

knowing HTML is not enough, you need to understand a little PHP and basic knowledge of WP's page hierarchy. I emphasized this on option 1.

Here's a link on how to create your own search.php page:


BTW. I believe you need to address the "white page" issue first. Try to disable plugins to know what's causing this.

And this has nothing to do with 404 pages as others suggest. 404 pages are for missing pages( page not found), not "not found" search results.


Good luck bro.
 
  • Like
Reactions: ImCesar
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock