DuckDuckGo WordPress search

Ben Brooks pointed out the official solution, which involves embedding a whole thing.

I just added this snippet to the very top of my WordPress theme’s index.php:

<?php if(is_search()) {
header('Location: http://duckduckgo.com/?q=site:joshuagoodwin.com+' . get_search_query());
} ?>

If your theme has a search.php file, it’s even easier:

<?php
header('Location: http://duckduckgo.com/?q=site:joshuagoodwin.com+' . get_search_query());
?>

This is cool because it works with any standard WordPress search form – even the one in the admin toolbar. And the search engine is probably better than the one built into WordPress. Obviously, do swap in the domain name of your own site, and you can get really fancy with URL parameters.

Update (30 January): Pat Dryburgh presents a superior alternative, which takes advantage of the undocumented sites parameter. I did beat my chest for some time, thinking that surely such an thing must exist – even Google has sitesearch – but I couldn’t find any mention in the documentation, there being none. (Why?) Fortunately, Dryburgh is all kinds of magic, so good for him.