Archived topic
Custom search trigger button
7 replies · Started by Daniel on February 2, 2023
Hi there!
I need to create a custom button that, when clicked, will load the GeneratePress search form. I need to put that search button in a block inside Gutenberg.
I want to know if that is possible. To create a button with a specific class or to use a shortcode to generate the GP search button and be able to place it inside a Gutenberg block.
Any other system that you recommend me and that I can include inside a Gutenberg block can be useful to me.
Thanks!
Hi Daniel,
Do you consider using the WP search block?
Hi Ying,
What I need is a button or something like the magnifier icon GP adds to the main menu that when clicked opens the search form template.
The WP search block is a search input and a search button. I can't use that block for what I want to achieve.
Where are you going to place the button? There's no easy way to use just a class to achieve this.
Let me know!
I need it for use within Gutenberg.
I don't care if it is a button, an icon or a shortcode that I can use to call the search template.
I don't know if in GP there is a function that generates the search button/icon. If there is such a function, maybe I can build it into a shortcode to display it where I need it.
You can give this code a try, using the [gp_navigation_search] shortcode.
function generate_navigation_search_shortcode() {
// Call the theme's built-in function
$navigaion_button = generate_do_navigation_search_button();
$search_form = generate_navigation_search();
$output = $navigaion_button .$search_form;
echo $output;
}
add_shortcode( 'gp_navigation_search', 'generate_navigation_search_shortcode' );
Thanks for the code, Ying.
Unfortunately, once I added the code to functions.php and inserted the shortcode, nothing is generated on the page.
Anyway, I have found a workaround to achieve what I needed, so I've got it solved.
Glad to hear that :)