[Resolved] How to trigger a non-native WordPress search with navigation search icon

Home Forums Support [Resolved] How to trigger a non-native WordPress search with navigation search icon

Home Forums Support How to trigger a non-native WordPress search with navigation search icon

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #468466
    verysiberian

    Hello! First, let me express how much I am enjoying GeneratePress and GP Premium. Thank you for such useful and powerful tools. I have found answers to all of my questions in the documentation thus far. There is only one matter about which I am perplexed.

    I use a non-native WordPress search service, AddSearch, for searches on two of my sites. They provide a plugin that overrides the native WP search function such that when someone performs a search using the search widget, their service is triggered instead of a standard WP search. This works as expected using the GeneratePress theme. However, I have found that when navigation search is enabled in GeneratePress that clicking on the magnifying glass icon still uses a standard WP search and leads to a results page. Doing so also causes a search box to appear in an odd part of the page (lower left corner of screen).

    I would appreciate any suggestions for having a click on the navigation search icon leading to an AddSearch search rather than the native WP search. This is the only conflict between that plugin/service (AddSearch) and GeneratePress that I have thus far detected. Thank you for any assistance!

    GeneratePress 2.0.1
    GP Premium 1.5.6
    #468545
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Glad you’re enjoying GP!

    The only thing I see is that service is adding a data attribute to the search box at the bottom of the site.

    We can add that data attribute to the navigation search using a filter: https://docs.generatepress.com/article/generate_navigation_search_output/

    For example:

    add_filter( 'generate_navigation_search_output', 'tu_navigation_search_data_attribute' );
    function tu_navigation_search_data_attribute() {
    	printf( 
    		'<form method="get" class="search-form navigation-search" action="%1$s">
    			<input type="search" data-addsearch-field="true" class="search-field" value="%2$s" name="s" title="%3$s" />
    		</form>',
    		esc_url( home_url( '/' ) ),
    		esc_attr( get_search_query() ),
    		esc_attr_x( 'Search', 'label', 'generatepress' )
    	);
    }
    #468551
    verysiberian

    Thank you very much, Tom! Works perfectly. ๐Ÿ™‚

    #468714
    Tom
    Lead Developer
    Lead Developer

    You’re very welcome ๐Ÿ™‚

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