0

I have the current function in my theme in order to alter Wordpress current search form:

function clarity_wpsearch($form) {
$form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
<label class="screen-reader-text" for="s">' . __('Search for:', 'claritytheme') . '</label>
<input type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="'.esc_attr__('Search the Site...','claritytheme').'" />
<input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
</form>';
return $form;

}

However, I would like to change the submit input to an image. I found this code for reference:

 <input type="image" alt="Search" src="<?php bloginfo( 'template_url' ); ?>/images/search.png" />

However, I have tried to integrate this code inside my function without luck, maybe it's a PHP issue I'm having, but I am having trouble figuring out.

Thanks a lot for your help!

2
  • 1
    Why do you want to change submit input to image input? You can add image to submit button using background-image css property. Sep 5 '13 at 14:03
  • Exactly what fails about your code? Do you get errors? What?
    – s_ha_dum
    Sep 5 '13 at 14:09
1

bloginfo( 'template_url' ) will print the URL to the page and break the return of your function.

You need to use get_bloginfo( 'template_url' ) to concatenate the result into the string.

function clarity_wpsearch($form) {
    $form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
    <label class="screen-reader-text" for="s">' . __('Search for:', 'claritytheme') . '</label>
    <input type="text" value="' . get_search_query() . '" name="s" id="s" placeholder="'.esc_attr__('Search the Site...','claritytheme').'" />
    <input type="image" alt="'. esc_attr__('Search') .'" src="'. get_bloginfo( 'template_url' ) .'/images/search.png" />
    </form>';
    return $form;
}
1
  • Hi @epilektric, this is exactly what I needed to figure out. I didn't knew how to write the proper PHP code in order to accomplish this.
    – Johann
    Sep 5 '13 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.