- This topic has 5 replies, 2 voices, and was last updated 3 years, 6 months ago by
David.
-
AuthorPosts
-
October 24, 2022 at 5:03 am #2383987
Daniel
Hello!
I used a code snippet I got from this forum to generate a new search form and display it in the hook: generate_after_header
The form is triggered from the magnifying glass icon in the GP menu.The code I am using is this:
add_action( 'after_setup_theme', function() { remove_action( 'generate_inside_navigation', 'generate_navigation_search' ); remove_action( 'generate_inside_mobile_header', 'generate_navigation_search' , 1 ); add_action( 'generate_after_header', 'generate_navigation_search' ); }); add_filter( 'generate_navigation_search_output', function($form) { $form = sprintf(' <form method="get" class="search-form navigation-search" action="%1$s"> <div class="search-form-container grid-container"> <input type="search" class="search-field" placeholder="Introduce aquí la palabra clave de tu búsqueda" value="%2$s" name="s" title="%3$s" /> <input type="hidden" name="post_type" /> <button class="search-submit" aria-label="%1$s"></button> </div> </form>', esc_url( home_url( '/' ) ), esc_attr( get_search_query() ), esc_attr_x( 'Search', 'label', 'generatepress' ), esc_attr__( 'Search', 'submit button', 'generatepress' ), generate_get_svg_icon( 'search', true ) ); return $form; });I want to know how to accomplish two things if possible.
One is to display the magnifying glass icon on the search button that is displayed next to the search box and now appears empty.
And the other is that when clicking on the magnifying glass icon in the main navigation I want the form to move from top to bottom with some css transition. I have tried with the height value but it didn’t work, is it possible to achieve this somehow?
Thanks!
October 24, 2022 at 7:45 am #2384158David
StaffCustomer SupportHi there,
try changing the snippet to:
add_action( 'after_setup_theme', function() { remove_action( 'generate_inside_navigation', 'generate_navigation_search' ); remove_action( 'generate_inside_mobile_header', 'generate_navigation_search' , 1 ); add_action( 'generate_after_header', 'generate_navigation_search' ); }); add_filter( 'generate_navigation_search_output', function($form) { $form = sprintf(' <form method="get" class="search-form navigation-search" action="%1$s"> <div class="search-form-container grid-container"> <input type="search" class="search-field" placeholder="Introduce aquí la palabra clave de tu búsqueda" value="%2$s" name="s" title="%3$s" /> <input type="hidden" name="post_type" /> <button class="search-submit" aria-label="%1$s">%4$s</button> </div> </form>', esc_url( home_url( '/' ) ), esc_attr( get_search_query() ), esc_attr_x( 'Search', 'label', 'generatepress' ), generate_get_svg_icon( 'search', true ) ); return $form; });Note the change to this line:
<button class="search-submit" aria-label="%1$s">%4$s</button>the
%4$srefers to the 4th argument ie.generate_get_svg_icon( 'search', true )For the other requirement – can i see the site ?
October 24, 2022 at 9:47 am #2384500Daniel
Hi David and many thanks for pointing me in the right direction!
I sent you the access to check the web.
Please tell me if it is possible to get the vertical scrolling effect to show the search form.
Thanks!
October 24, 2022 at 10:07 am #2384514David
StaffCustomer SupportTry this CSS:
/* SEARCH BAR */ .navigation-search { position: relative; max-width: 1200px; margin: auto; left: unset !important; visibility: unset !important; width: auto !important; max-height: 0; overflow: hidden; transition: all 0.3s ease-in; } .navigation-search.nav-search-active { position: relative; max-height: 100px; top: 0; right: 0; z-index: 10000; background-color: var(--contrast-2); display: flex; align-items: center; } .search-form-container { display: flex; flex-wrap: wrap; align-items: center; width: 100%; max-width: 800px; padding: 20px; } .navigation-search input[type="search"] { width: auto; flex: 1; color: var(--contrast-2); background-color: #fff; } .navigation-search .search-submit { padding: 16px 20px; background-color: var(--base); }October 24, 2022 at 10:40 am #2384538Daniel
Perfect!
I really like this way of displaying the search form. I will use it in future websites I develop.
Thank you very much!
October 25, 2022 at 2:08 am #2385114David
StaffCustomer SupportI like it too – looks great 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.