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 wanted to override the wordpress default search with my custom search, however when i put the following code in the plugin file it doesn't appear replace the default searchbox(no error, nothing) and when i put the code in functions.php it works fine and replaces the default searchbox.

Can anyone tell me why is it not working in plugin file? Thanks!

function DynamiteSearch($form) {
    $form = '<form method="get" id="searchform" action="' . get_option('home') . '/" >
    <div><label class="hidden" for="s">' . __('Search for:') . '</label>
    <input type="text" value="' . attribute_escape(apply_filters('the_search_query', get_search_query())) . '" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="'.attribute_escape(__('Search')).'" />
    </div>
    </form>';
    return $form;
}

add_filter('get_search_form', 'DynamiteSearch');
share|improve this question
3  
Are you sure the plugin is activated? If it is, it would help if you could post the entire plugin file. –  scribu Apr 17 '11 at 8:15
    
My plugin only has this much of code with regular plugin header. I am able to activate the plugin as normally, no problem with that. –  ravenarvind Apr 18 '11 at 11:24
add comment

2 Answers

I cleaned up your code, and put all the header information for installing it. Your plugin works fine, I tested it!

/*
Author: whoever
Plugin Name: Some Name
Plugin URI: 
Text Domain: some-domain
Version: 1.0
*/

function DynamiteSearch($form) 
{
    $form = "<form method = 'get' id = 'searchform' action = ' ".site_url()." ' >";
    $form .= "<div><label class = 'hidden' for='s'>". __("Search for: ") . "</label>";
    $form .= "<input type = 'text' value=' ". attribute_escape(apply_filters('the_search_query', get_search_query())) ." ' name='s' id='s' />";
    $form .= "<input type = 'submit' id='searchsubmit' value=' ".attribute_escape(__('Look for it'))." ' />";
    $form .= "</div>";
    $form .= "</form>";

    return $form;
}

add_filter('get_search_form', 'DynamiteSearch');

Try changing the submit button text to see if it works. Let me know if it worked for you.

Thanks, Rutwick

share|improve this answer
    
Thanks Rutwick! But for some reason the searchbox on my site still doesn't change. Were you able to change the searchbox with this code? thanks for letting me know. –  ravenarvind Apr 18 '11 at 11:21
    
Yes Arvind... I tested it by changing the button text and it showed up well. I'm using 'TwentyTen' theme... –  Rutwick Gangurde Apr 18 '11 at 15:38
1  
Are you using a caching Plugin, or a CDN, or any other form of caching that might be preventing you from seeing the modified output? –  Chip Bennett Jun 16 '11 at 17:06
add comment

If the code you've posted is literally all the code you're placing into the file, that'll be why.

Firstly you need plugin headers at the top of the file, eg..

/*
    Author: whoever
    Description: whatever
    Domain Path: /lang
    Plugin Name: Some Name
    Plugin URI: 
    Text Domain: some-domain
    Version: 1.0
*/

Secondly you need to activate the plugin from the plugins admin page(Admin > Plugins), but it'll only appear in that list once the plugin has a valid header, like the one posted above.

If neither of those two things is the problem, please post up more of your code(there must be more, because you're missing the plugin headers from what's posted)..

Hope that helps.. :)

share|improve this answer
add comment

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.