Site logo

Archived topic

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

3 replies · Started by verysiberian on January 11, 2018

Viewing posts 1–4 of 4

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!

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' )
	);
}

Thank you very much, Tom! Works perfectly. :)

You're very welcome :)

This archived topic is closed to new replies.