Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
1  
Why do you want to change submit input to image input? You can add image to submit button using background-image css property. –  Vinod Dalvi 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 Answer 1

up vote 1 down vote accepted

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;
}
share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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