简体   繁体   中英

Parse error: syntax error, unexpected 'search' (T_STRING)

Hi guys I new to this and I'm trying to create a search form, but seems to be a problem with my function php file. I know for fact that the problem is in my "if" statement but I have no clue if there's any other option that i could use to make it work. Here's the code:

function my_search_form( $form ) {
$form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
<input type="text" name="s" id="search" align="center" size="30" value="' . get_searchform() . '" onfocus="if(this.value ==  . 'search & hit enter' . ) { this.value =  . '' . ; }" onblur="if(this.value ==  . '' . ) {this.value =  . 'search & hit enter' . ; }" />
<input type="hidden" value="post" name="post_type" id="post_type" />
</form>';

return $form;

}

add_filter( 'get_search_form', 'my_search_form' );
search & hit enter

This part is invalid code, it needs to be escaped

function my_search_form( $form ) {
    $form = '
    <form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
        <input type="text" name="s" id="search" align="center" size="30" value="' . get_searchform() . '" onfocus="if(this.value == \'search &amp; hit enter\') { this.value = \'\'; }" onblur="if(this.value == \'\') {this.value =\'search &amp; hit enter\'; }" />
        <input type="hidden" value="post" name="post_type" id="post_type" />
    </form>';

    return $form;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM