Adding a search form inside a div

I wanted to add a search form inside a div using the code bellow:

printf( '<div class="entry"><p>%s</p>%s</div>', apply_filters( 'genesis_noposts_text', __( 'Try again below.', 'genesis' ) ), get_search_form() );

But every time I add the get_search_form() it’s generated before the div, like the following:

<form></form>
<div class="entry"></div>

The workaround I found was to split the code, but I wanted to know if there is a better solution that works properly.

remove_action( 'genesis_loop_else', 'genesis_do_noposts' );
add_action( 'genesis_loop_else', 'mytheme_do_noposts' );
function mytheme_do_noposts() {

    printf( '<div class="entry"><p>%s</p>', apply_filters( 'genesis_noposts_text', __( 'Try again below.', 'genesis' ) ) );

    printf( '%s</div>', get_search_form() );

}

get_search_form

2 Answers
2

The get_search_form() echos so it will always show up before returns. Use:

get_search_form( false )

Leave a Comment