• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to user navigation

PopWP

WordPress and Genesis Tutorials

  • Get Started
  • About
  • Archive
  • Services
  • Membership
  • My Account

Display Search form Widget on Custom Page

Last Updated on August 14, 2018 Favorited: 0 times

This tutorial provides the steps to add a search form on the front page, post page or any post or page in Genesis. The tutorial uses default functions to add the search form.

TYPE 1

You can create a shortcode for the search function and then output the shortcode in a location using a conditional tag.

STEP 1

Create a shortcode and write a function for it. Add the following in functions.php

add_action( 'init', 'register_custom_shortcode' );
/**
* Register the Shortcode.
*/
function register_custom_shortcode() {
	add_shortcode( 'search-bar', 'search_box_type' );
}

/**
* Search Shortcode Output
*/
function search_box_type() {
	return '<div class="search-bar">' . get_search_form( false ) . '</div>';
}

STEP 2

Output the shortcode using Genesis hook location and WordPress conditional tag. Add the following in functions.php

add_action('genesis_before_loop', 'gk_search_shortcode');
function gk_search_shortcode() {
if ( ! is_home() ) {
		return;
	}
    echo do_shortcode('[search-bar]');
}

TYPE 2

You can simply output the search form without using a shortcode. Add the following in functions.php

//* Add search form to site header
add_action( 'genesis_before_loop', 'genesiskit_search', 13 );
function genesiskit_search() {
	if ( ! is_home() ) {
		return;
	}
	//search form.
	get_search_form();
}

Your turn:

a) Change genesis_before_loop hook location using Genesis Visual Hooks guide.

b) change is_home() conditional tag using WordPress Conditional Tags.

Related Posts

  • Expanding Search box in menu-item list in Genesis
  • Pop Up Search to the right Site Header in Genesis
  • Search Form in primary menu in Genesis
  • Custom Widget area having Categories and search on Post Page in Genesis
  • Custom hero title on Search results Page in Genesis

Categories: Free Content, Genesis Tutorials Tags: search, search widget

Reader Interactions

Primary Sidebar

Search

WPEngine WordPress Hosting, Perfected.

Hosting You are looking for?.
Perfect solution for small business to global enterprise.

Learn more

StudioPress Genesis Theme Framework

The No.1 Theme Provider.
Creative, SEO rich Theme for all niche projects.

Learn more

Categories

  • Free Content
  • Genesis Tutorials
  • Premium Content
  • Snippets
  • What's New?
  • WordPress Tutorials

Tag Cloud

Archive Background Section blog canvas menu center logo columns conditional tags CSS CSS Grid custom Customizer custom post type Custom Post Types custom template Custom Widget effect eNews Extended Featured Image front-page Genesis Genesis Sample header right hero section Image Background js layout left menu Logo menu Navigation Menu newsletter post page related posts responsive menu search search widget Shrinking Logo site header slide in-out Stylesheet Template Utility Bar Video Background widgets WordPress

Built with Genesis Framework + WordPress by Aryan Raj

  • Contact
  • FAQ
  • Disclaimer
  • Privacy Policy
  • Copyright Policy
  • Terms of Service