Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Show suggestions only when search is opened
- This topic has 5 replies, 2 voices, and was last updated 3 years, 6 months ago by
Ernest Marcinko.
-
AuthorPosts
-
December 2, 2022 at 3:51 pm #40356
Heizpad
ParticipantHi there!
Currently the suggestions appear beneath the search field (like on your example website “Try these: example elementor woocommerce blog”). Is it possible to make them appear inside the popup when you start a search. So not on initial load but only when you click inside the search bar?
Thank you
December 2, 2022 at 4:50 pm #40365Ernest Marcinko
KeymasterHi,
Well, there is no option to do that, but it might be doable via some custom code. Basically the initial opacity of the phrases container would be set to 0 (invisible) via custom CSS, then a javascript removes that once the input is focused.
Apply this code to your theme custom CSS field (if it supports it) or use the custom CSS field on the search plugin back-end.
p[id*=asp-try-] { opacity: 0; }Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.
add_action('wp_footer', 'asp_footer_custom_script', 999999); function asp_footer_custom_script() { ?> <script> jQuery(function($){ $('input.orig').on('focus', function(){ $('p.asp-try').css('opacity', 1); }); }); </script> <?php }I believe this is as close as it gets.
December 2, 2022 at 6:22 pm #40368Heizpad
ParticipantHi again!
Thank you, I really appreciate your efforts here. However, when the input field is out of focus again the suggestions still stay there. Is it possible to remove them again once the user is out of focus?
Thank you
December 5, 2022 at 10:43 am #40385Ernest Marcinko
KeymasterThat should be doable too. Please use this instead of the second suggested code:
add_action('wp_footer', 'asp_footer_custom_script', 999999); function asp_footer_custom_script() { ?> <script> jQuery(function($){ $('input.orig').on('focus', function(){ $('p.asp-try').css('opacity', 1); }).on('blur', function(){ $('p.asp-try').css('opacity', 0); }); }); </script> <?php }This will restore the invisibility too, when the input gets out of focus.
December 5, 2022 at 1:39 pm #40394Heizpad
ParticipantWorks perfectly without any issues so far, thank you very much again!
December 5, 2022 at 2:33 pm #40403Ernest Marcinko
KeymasterYou cannot access this content.
-
AuthorPosts
- You must be logged in to reply to this topic.