- This topic has 20 replies, 3 voices, and was last updated 4 years, 1 month ago by Tom.
-
AuthorPosts
-
January 28, 2020 at 10:25 am #1147364Michael
Hi all,
I have implemented the snippet to change the navigation search placeholder text and that works fine:
https://www.dropbox.com/s/tl3vokeyg7rqrf0/nav-search-placeholder.jpg?dl=0
However on the results page, the 2 search boxes get populated with the search term I have just searched for, and if I delete this, then the placeholder text reverts to “Search…”
How can I get the placeholder text on these to show up as per the navigation search placeholder, and do so without first auto-populating with the previous search term?
https://www.dropbox.com/s/n3d0uxg0fcgdsle/search-results-page.jpg?dl=0
Many thanks.
Michael.
The url I am testing on: https://reclaimdesign-383226.easywp.com/about-reclaim-design.html
January 28, 2020 at 2:45 pm #1147581LeoStaffCustomer SupportHi there,
Any chance you can link us to the site in question?
You can edit the original topic and use the private URL field.
Let me know π
January 28, 2020 at 11:32 pm #1147796MichaelHi Leo, I’ve done that now π
January 28, 2020 at 11:46 pm #1147807MichaelAlso, it is returning some odd results. If I enter “test” it brings up my About page in the results? I know that I don’t have much content at the moment, but I would imagine “test” should bring up a “No Results Found”.
https://www.dropbox.com/s/6s27f77wsljew2u/test-result.jpg?dl=0
And if I click search without entering anything into the box, it returns my menu options in a column:
https://www.dropbox.com/s/x2cjhe4uwh2zyn6/blank-input-results.jpg?dl=0
I would have expected it to not submit on a blank input, like the Google search I have running on our live site:
And one last question on the search front – is it possible to set it up so that it returns images (as per the search box on our site above)? The people who are searching our site are generally looking for product images rather than info, and tend to do better visually
January 29, 2020 at 9:15 am #1148419TomLead DeveloperLead DeveloperHi there,
We can remove the current search result by tweaking the filter. Can you share the current filter you’re using to change the placeholder?
Your about page is showing up when you search for “Test” because you have the word “Test” at the top of the page.
WordPress itself displays everything if the search query is empty. However, we may be able to add
required
to the HTML element itself in the same filter to prevent this.January 29, 2020 at 9:40 am #1148436MichaelHi Tom, thanks for getting back to me.
I’ve just changed the “Test” text to read “Placeholder” and if I do a search for “test” it still shows my about page for some reason. As far as I can tell “test” isn’t in the text anywhere else on that page.
https://reclaimdesign-383226.easywp.com/about-reclaim-design.html
Here is the code snippet I added:
add_filter( 'generate_navigation_search_output', function() { printf( '<form method="get" class="search-form navigation-search" action="%1$s"> <input type="search" placeholder="Search Our Eco-friendly Home Decor" class="search-field" value="%2$s" name="s" title="%3$s" /> </form>', esc_url( home_url( '/' ) ), esc_attr( get_search_query() ), esc_attr_x( 'Search', 'label', 'generatepress' ) ); } );
And then to style the colour of the input text I added this to the CSS:
.navigation-search input[type="search"], navigation-search input[type="search"]:focus { opacity: 1; } .navigation-search input[type="search"]::placeholder { color: #fff; } .navigation-search input[type="search"]::-webkit-input-placeholder { color: #fff; } .navigation-search input[type="search"]::-moz-placeholder { color: #fff; } .navigation-search input[type="search"]::-ms-placeholder { color: #fff; }
I had to adjust the opacity because the menu items were showing up behind. I had a hell of a time trying to get the font to stay white across all browsers – I’m not sure that that the above code I added is actually working all that well since on my phone the input text kept showing up as the same grey colour as the body, but only after I did a search. Initially it was fine…. Really weird.
January 29, 2020 at 4:19 pm #1148728TomLead DeveloperLead DeveloperTry changing it to this:
add_filter( 'generate_navigation_search_output', function() { printf( '<form method="get" class="search-form navigation-search" action="%1$s"> <input type="search" placeholder="Search Our Eco-friendly Home Decor" class="search-field" value="" name="s" title="%3$s" required /> </form>', esc_url( home_url( '/' ) ), esc_attr( get_search_query() ), esc_attr_x( 'Search', 'label', 'generatepress' ) ); } );
WordPress doesn’t have a great search system. It’s likely seeing latest in the text and returning it as a result for test.
January 30, 2020 at 4:01 am #1149130MichaelHi Tom, I’ve updated that code and if I enter “test” it still returns Latest and About pages
January 30, 2020 at 9:05 am #1149552TomLead DeveloperLead DeveloperThere’s not much we can do about that, unfortunately. That’s the search system inside WordPress itself.
Not sure if a plugin like this will help, but it’s worth a shot: https://wordpress.org/plugins/relevanssi/
January 30, 2020 at 10:38 pm #1149975MichaelThanks Tom, I will give that a shot
January 31, 2020 at 12:19 am #1150012MichaelHi Tom,
I’ve installed that plugin and wrote to the developer to ask if it is possible to return images in the results as opposed to text (as per the Google Custom Search), and he said:
What happens on the search results page depends on your theme. Relevanssi can be set to search media library, but it’s up to your theme what is shown on the search results page.
How do I set the theme to do as he suggests?
Michael.
January 31, 2020 at 10:49 am #1150716TomLead DeveloperLead DeveloperI’m not sure what you mean – how would you return only images in the search results? Any examples?
February 1, 2020 at 6:49 am #1151301MichaelHi Tom,
I mean something like this (from the google custom search results on my site – https://www.reclaimdesign.org)
https://www.dropbox.com/s/1m8ls7c23hw3z2c/google-custom-search-image-results.jpg?dl=0
As to how you would do it? I have absolutely no idea π
February 1, 2020 at 10:42 am #1151534TomLead DeveloperLead DeveloperWe can hide things other than the images in your search results if you’d like? WordPress will still base its search on the content of the page (not the image itself).
February 1, 2020 at 12:27 pm #1151606MichaelHi Tom, I think the Google search must be looking at alt tags and image sitemap or some such. Anyway, if it’s not possible no worries.
-
AuthorPosts
- You must be logged in to reply to this topic.