WordPress stuck at briefly unavailable for scheduled maintenance

Today while updating a plugin, update window got stuck at following image,

Wordpress scheduled maintenance message

Wordpress scheduled maintenance message

And I was not able to figure out why was it. Then I went back to the update page and saw the following message,

Enabling maintenance mode in wordpress

Enabling maintenance mode in wordpress

Here you can see the wordpress enables maintenance mode before pushing any update. But what if  update is not completed successfully?

If update does not happen successfully your page gets stuck on above image and your site shows message in first image.

How can you remove this annoying messages? After googling out I figured out wordpress creates a .maintenance page in the root directory where your wordpress is installed. You need to delete this file, which I did. After deleting the site was up again.

Wordpress maintenance file

Wordpress maintenance file

But this happened everytime I tried to update that plugin. So I searched for place where wordpress was checking if it is in maintenance mode.

WordPress has a file called as “wp-settings.php” in the root directory. It has line of code that checks if maintenance mode is enabled. So just comment that line and wordpress will not go in maintenance mode again.

Bypass maintenance mode check in wordpress

Bypass maintenance mode check in wordpress

It will show you the message enabling maintenance mode but still your site will be up.

Hope this helps.

How to prevent image from caching in javascript

Many a times when we replace the image with the same name, browser still picks up the old one. Almost every developer faces this issue, then he asks the person to clear the cache by ctrl + F5 or any other means. But is this the solution?

No, So what can we do in this case? There are two solutions,

1 – rename the new image and change the image name in code. But for a dot net developer this is pain because he may have to republish the code and send an upload of the dll again. And giving an upload of dll because of change in image is foolishness, ain’t it?

2 – Another solution is to write a javascript code so that the browser does not pick up image from the cache and loads it everytime. Following is the sample code of how you can try this,

document.getElementById('myimg').src = document.getElementById('myimd').src + '?' + (new Date()).getTime();

You need to make sure this code runs after page has loaded else, it will give an error if that image tag is not yet rendered.

In JQuery for single image code will be

$(document).ready(function(){
$("#myimg").attr('src',$(this).src + '?' + (new Date()).getTime());
});

For all the images

$(document).ready(function(){
jQuery('img').each(function(){
jQuery(this).attr('src',jQuery(this).attr('src')+ '?' + (new Date()).getTime());
});
});

Hope this helps. If you have any more idea please share it with us by dropping a comment.