Doc WordPress WordPress Tricks, Tips & Snippets


Allow empty search

The default WordPress search function just redirects you to the home page should the search form be empty, which can be confusing for the visitors. Should you prefer to correctly display the search result page with a "Sorry your search returned no results instead" message you can fix this by adding this code to your functions.php:

add_filter( 'request', 'my_request_filter' );
function my_request_filter( $query_vars ) {
    if( isset( $_GET['s'] ) && empty( $_GET['s'] ) && !is_admin()) {
        $query_vars['s'] = " ";
    return $query_vars;

You can test this behaviour right here on


Remove unnecessary stuff from WordPress header

By default WordPress adds quite some meta junk to your site's <head>. Luckily for us these can easily be disabled without the need to install a plugin for this (remember: the less plugins the better). Just add this to your website's functions.php (found in your theme folder):

remove_action('wp_head', 'wp_generator'); // remove wp version header
remove_action('wp_head', 'wlwmanifest_link'); // remove MS-live writer
remove_action('wp_head', 'rsd_link'); // remove Really Simple Discovery
remove_action( 'wp_head', 'feed_links_extra', 3 ); // remove Comments Feed


Stop WordPress asking for FTP details when trying to install or update plugins

Depending on your server's settings and file permissions your WordPress system might not be allowed to update or install plugins by itself, causing it to ask for FTP access data whenever you try it. Manually entering those can be time consuming and annoying, luckily there is a better way!

You can actually define the FTP credentials permanently in the wp-config.php (found in the root of your WP install) and by doing so prevent WordPress from ever nagging you again. Just add this code to your wp-config.php:

/** Setup FTP Details **/
define("FTP_HOST", "localhost");
define("FTP_USER", "the-ftp-username");
define("FTP_PASS", "the-ftp-password");

Don't forget to replace the FTP_HOST, FTP_USER and FTP_PASS with the real access credentials.