Skip to content

Instantly share code, notes, and snippets.

@Isabellae4567
Created December 25, 2023 14:47
Show Gist options
  • Select an option

  • Save Isabellae4567/c16a242c51543230bda96d91de89a397 to your computer and use it in GitHub Desktop.

Select an option

Save Isabellae4567/c16a242c51543230bda96d91de89a397 to your computer and use it in GitHub Desktop.
To add a search bar at the top of the sidebar in your GeneratePress websit
// Add search bar to the top of the sidebar
function add_search_bar_to_sidebar() {
?>
<div class="custom-sidebar-search">
<?php get_search_form(); ?>
</div>
<?php
}
add_action('generate_before_sidebar_content', 'add_search_bar_to_sidebar');
@Isabellae4567
Copy link
Author

This code uses the get_search_form() function to output the default search form in WordPress. It then adds this search form to a custom div with the class custom-sidebar-search. You can customize the styling of this search bar by adding CSS to your theme.

Remember to test this code in a safe environment before applying it to your live website. Additionally, make sure you have a backup of your theme files or use a child theme to avoid losing your changes during theme updates.

To see the sample of this search bar you can see http://spotypre.com/.

@7brewcoffeemenus-a11y
Copy link

i added this code to my site (https://7brewcoffemenu.com/ please check the sample

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment