[Support request] Add Search to anywhere on page!

Home Forums Support [Support request] Add Search to anywhere on page!

Home Forums Support Add Search to anywhere on page!

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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 Thanks

    #2353805
    Fernando
    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.

    #2353820
    Sy

    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

    #2354360
    Ying
    Staff
    Customer Support

    In that case, you can add the search block into your generate_before_header hook element.

    #2354783
    Sy

    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!

    #2354791
    Fernando
    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]

    #2356104
    Sy

    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

    #2356782
    Ying
    Staff
    Customer Support

    Can you make sure the navigation search is enabled at customizer > layout > primary navigation?

    #2357481
    Sy

    Excellent! Thank you

    #2357986
    Ying
    Staff
    Customer Support

    No problem 🙂

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.