Site logo

Archived topic

Search form within a page possible?

3 replies · Started by Roman on February 18, 2017

Viewing posts 1–4 of 4

Hi Roman,

You could build a shortcode which you can use like this:

add_shortcode( 'search', 'tu_search_shortcode' );
function tu_search_shortcode() {
	ob_start();
	get_search_form();
	$ret = ob_get_contents();
	ob_end_clean();
	return $ret;
}

Then just use [search] in your content.

Hello Tom. Revisiting this, but tell me if I should start a new topic. Is there a way to constrain this search to the page that it's on? For example, there are a lot of things on a site that I'm building related to the same words, but I only want to see results on the one page where I put the search bar. Possible?

I don't think it's possible to modify WordPress get_search_form(); this way.

Might be worth asking on a general forum like this and see if anyone has a clever solution:
https://wordpress.stackexchange.com/

This archived topic is closed to new replies.