6 Useful WordPress hooks

1. Hide your WordPress login error: 

Login errors with multiple details can give away the information required to help gain access to the site. With the facility of the code provided below, WordPress will not spot out where the error is made while attempting to log in. The purpose of the code is to not provide any user the hints necessary for logging-in.

add_filter( ‘login_errors’, ‘ hide_wordpress_errors’ );
function hide_wordpress_errors(){
  return 'Something is gone wrong!';


2. Enable WordPress to accept any file format:

By default, WordPress allows us to upload a limited range of file types, including media formats such as .png and .jpg. With the facility of the code provided below, you’ll be able to force installation to allow more file formats.

add_filter(‘upload_mimes’, ‘my_myme_types’, 1, 1);
function my_myme_types($mime_types){
 $mime_types[‘svg’] = ‘image/svg+xml’;
 return $mime_types;


3. Disabling the WordPress search feature: 

Almost every site needs a search feature to help users find their way in the website. However, if we are going to build a single-page website, we might not require the search bar feature. Here’s the code that will enable you to turn it off:

function wi_filter_query( $query, $error = true ) {
if ( is_search() ) {
 $query->is_search = false;
 $query->query_vars[s] = false;
 $query->query[s] = false;
 // to error
 if ( $error == true )
  $query->is_404 = true;

add_action( 'parse_query', 'wi_filter_query' );
add_filter( 'get_search_form', create_function( '$a', "return null;" ) );


4. Remove the Admin Toolbar:

As an admin of a page, we might receive a list of notifications and some of us might probably not be interested to check. WordPress makes it all easy by making us allow to disable or remove the toolbar on the page which provides a comfort zone for the users.

add_filter(‘show_admin_bar’, ‘__return_false’);


5. Change the Login Logo hyperlink in WordPress:

WordPress enables us to change the login logo link. Using the provided hook, we can change the logo to make it user-friendly and prevent the user from navigating to WordPress website when clicked on the logo.

add_filter( ‘login_headerurl’, ‘custom_loginlogo_url’ );
function custom_loginlogo_url($url) {
  return 'http://wpisle.com';

6. Change the login Logo with your site logo 

For some reason, we have decided to replace WordPress logo with a custom image probably the site logo. WordPress allows it and there is no restriction we can simply pull this off using the below hook.

function my_login_logo() {
print ' <style type="text/css">
 #login h1 a, .login h1 a {
 background-image: url('.get_stylesheet_directory_uri().'/images/site-login-logo.png);
 background-size: 320px 65px;
 background-repeat: no-repeat;
 padding-bottom: 30px;

add_action( 'login_enqueue_scripts', 'my_login_logo' ); 

Posted in Hooks.

Vinesh is a WordPress Developer at WP ISLE. specialized in theme customization and WPBakery page builder.

Leave a Reply

Your email address will not be published. Required fields are marked *

seventeen + ten =