Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create a Search Form under Entry Title in Genesis
//* STEP #1: ADD EXCERPT SUPPORT TO PAGES
add_post_type_support( 'page', 'excerpt' );
//* Output Excerpt on Pages
add_action( 'genesis_meta', 'lwp_page_description_meta' );
//* STEP #2: REPLACE DEFAULT ENTRY HEADER WITH EXCERPT
function lwp_page_description_meta() {
//* If it's a singular page, apply page description
if ( is_singular() && is_page() && has_excerpt() ) {
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
add_action( 'genesis_after_header', 'lwp_open_after_header', 5 );
add_action( 'genesis_after_header', 'lwp_add_page_description', 10 );
add_action( 'genesis_after_header', 'lwp_close_after_header', 15 );
}
//* If it's the blog page, apply page description
if ( is_home() && has_excerpt() ) {
add_action( 'genesis_after_header', 'lwp_open_after_header', 5 );
add_action( 'genesis_after_header', 'lwp_add_page_description', 10 );
add_action( 'genesis_after_header', 'lwp_close_after_header', 15 );
}
}
function lwp_open_after_header() {
echo '<div class="after-header"><div class="wrap">';
}
function lwp_close_after_header() {
echo '</div></div>';
}
//* STEP #3: ADD A SEARCH FOROM BELOW EXCERPT TITLE ON BLOG HEADER
function lwp_add_page_description() {
//* If it's a singular page, add page-description class, a page title and then the page excerpt
if ( is_singular() && is_page() && has_excerpt() ) {
echo '<div class="page-description">';
echo '<h1 itemprop="headline" class="page-title">' . get_the_title() . '</h1>';
echo '<p>' . get_the_excerpt() . '</p></div>';
}
//* If it's the blog page, add page-description class, a page title and then a search form
if ( is_home() && has_excerpt() ) {
echo '<div class="page-description">';
echo '<h1 itemprop="headline" class="page-title">' . esc_attr( 'Enter your queries in the search form below to find the best answer.' ) . '</h1>';
echo '<p>' . get_search_form() . '</p></div>';
}
}
//* STEP #4: ENQUEUE DASHICONS (OPTIONAL)
//* Enqueue Dashicons
add_action( 'wp_enqueue_scripts', 'enqueue_dashicons' );
function enqueue_dashicons() {
wp_enqueue_style( 'dashicons' );
}
//* STEP #5: ADD A GLASS ICON TO YOUR SEARCH BUTTON
//* Customize search form input button text
add_filter( 'genesis_search_button_text', 'lwp_search_button_text' );
function lwp_search_button_text( $text ) {
return esc_attr( '&#xf179;' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment