我想使用下面的代码在 div 中添加一个搜索表单:
printf( '<div class="entry"><p>%s</p>%s</div>', apply_filters( 'genesis_noposts_text', __( 'Try again below.', 'genesis' ) ), get_search_form() );
但是每次我get_search_form()
在 div 之前添加它时,它都会生成,如下所示:
<form></form>
<div class="entry"></div>
我找到的解决方法是拆分代码,但我想知道是否有更好的解决方案可以正常工作。
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() );
}