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.