- This topic has 9 replies, 3 voices, and was last updated 1 year ago by
Ying.
-
AuthorPosts
-
September 26, 2022 at 1:44 am #2353801
Sy
Hi all,
I’ve looked around the forum for the answer to this but I can’t find anything (I may of missed it though!)
I would like to add search to a top bar I’ve created with GP and GB, but the GP search function seems to be only available if you have a navigation menu set up. The top bar I’ve created doesn’t have any navigation menus in it. It consists of social media icons and a phone number. I wanted to add a search function as well to the top bar.
I’m sorry if this has already been answered before!
Many ThanksSeptember 26, 2022 at 1:49 am #2353805Fernando Customer Support
Hi Sy,
One approach is to go to Appearance > Widgets > Top Bar, and add a WordPress Search Block there. You may also do this in Appearance > Customize > Widgets > Top bar.
September 26, 2022 at 2:05 am #2353820Sy
Thank you for the super quick reply! Sorry, I should of mentioned, I’ve created the top bar in Elements > Block > Hook > generate_before_header. Would that still work?
Thanks
September 26, 2022 at 10:36 am #2354360Ying
StaffCustomer SupportIn that case, you can add the search block into your
generate_before_header
hook element.September 26, 2022 at 10:48 pm #2354783Sy
Thank you for your reply Ying, But, I mean the GP search magnifying glass not the WP native search block as it doesn’t look that good!
Thanks!
September 26, 2022 at 11:01 pm #2354791Fernando Customer Support
Add this PHP snippet:
function portable_func($atts, $content = null) { ob_start(); do_action('portable_hook'); return ob_get_clean(); } add_shortcode('portable-hook-shortcode', 'portable_func'); add_action( 'wp', function() { if ( 'enable' === generate_get_option( 'nav_search' ) ) { remove_action( 'generate_menu_bar_items', 'generate_do_navigation_search_button' ); add_action( 'portable_hook', 'generate_do_navigation_search_button' ); remove_action( 'generate_inside_navigation', 'generate_navigation_search' ); add_action( 'portable_hook', 'generate_navigation_search' ); } }, 20 );
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Then add this Shortcode in your Element through a Shortcode Block –
[portable-hook-shortcode]
September 28, 2022 at 1:41 am #2356104Sy
Thank you for providing the code. I added the PHP to Code Snippets and activated it then added a Shortcode block to the page but nothing appears, have I missed something out somewhere?
Thanks
September 28, 2022 at 12:33 pm #2356782Ying
StaffCustomer SupportCan you make sure the navigation search is enabled at customizer > layout > primary navigation?
September 29, 2022 at 4:08 am #2357481Sy
Excellent! Thank you
September 29, 2022 at 10:35 am #2357986Ying
StaffCustomer SupportNo problem 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.