How to enable maintenance mode in Magento

This article describes how to enable maintenance mode in Magento. When Magento is in maintenance mode, visitors see a Service Temporarily Unavailable message in their web browsers instead of the store. However, authorized IP addresses can still view the store normally.

This feature allows you to develop and test your store before it goes “live,” or do other maintenance tasks, such as installing updates.

To set Magento in maintenance mode you need to create a file with name “maintenance.flag” and drop it to Magento home directory. While this file exists your website visitors will see a temporary page (/errors/503.php). If you want to edit this page content you can find it in Magento admin – CMS/Pages, it is called “503 Service Unavailable”.

Once you finished with changes and your website is ready to work just delete maintenance.flag file and maintenance mode will be off, so your Magento website will work as usual.

All we need to do it edit 3 lines.

Open: index.php in root and above line 57 add (remembering to edit the ‘allowed’ array to contain the IP’s you want to be able to access the site);

$ip = $_SERVER['REMOTE_ADDR'];
$allowed = array('1.1.1.1','2.2.2.2'); // these are the IP's that are allowed to view the site.

then change the line
if (file_exists($maintenanceFile)) {
to
if (file_exists($maintenanceFile) && !in_array($ip, $allowed)) {

Simple. Now you can access the site, while others see its maintenance mode.

Know android codes for mobile device

Android codes for mobile device

1- For IMEI NUMBER :

*#06#

2- for Ram

*#*#3264#*#*

3- Phone service menu

*#0*#

4- Battery Status

*#0228#

5- phone service mode

*#9090#

6- Battery use or device related information

*#*#4636#*#*

7- Camera related inforamtion

*#*#34971539#*#*

8 – Software/Hardware information

*#12580*369#

Fix 404 error in WordPress category / tag page

Fix 404 error in WordPress category / tag page

Sometimes, especially after switching themes, WordPress will generate 404 errors on the category and tag pages. There might be multiple reasons – and also multiple solutions – to this, here is simple solution and it will fix the issue

Go to your WordPress backend, click Settings, click Permalinks. Make sure the category base is “category” and the tag base is “tag” (unless you have some VERY weird special settings) and simply press the “save changes” button. Even if nothing has changed, clicking the button will probably make your category and tag pages work again now.

Oh, Finally Don’t forget to clear the cache…. 🙂

 

Fix wordpress post 404 error

WordPress is fantastic CMS. Most of the world love it feature and flexibility. I am always try to recommend my clients to use this. Sometimes wordpress users face common problems and one of them in posts 404 error. Today we will learn how we can fix this issue.

This is the simple setting we can do fix this issue easy way.

Go to Settings » Permalinks, and simply click on Save Changes button. This will update your permalinks settings and flush rewrite rules. In most cases this solution fixes theWordPress posts 404 error. However, if it does not work for you, then you probably need to update your .htaccess file manually.

Login to your server using FTP, and modify the .htaccess file which is located in root folder. The easiest thing you can do is to temporarily make the file writeable by changing the permissions to 644.  You can should manually add this code if that is not alreay in in .htaccess file. If .htaccess file not available then you must upload this file.

# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Redirect all url to https

Redirect all url to https

If you have a secure certificate (SSL) on your website, you can automatically redirect visitors to the secured (HTTPS) version of your website to make sure their information is protected.

Using the following code in your .htaccess file automatically redirects visitors to the HTTPS version of your site:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

If you have an existing .htaccess file:

  • Do not duplicate RewriteEngine On.
  • Make sure the lines beginning RewriteCond and RewriteRule immediately follow the already-existing RewriteEngine On.

How To Create WordPress Shortcodes

WordPress introduced the shortcode API in version 2.5. Shortcodes are now used by a large number of WordPress plugins to allow users to add content to their posts and pages. All of us have probably used them at one time or another. They usually come bundled with plugins, or even themes, and what they do is watch for when you insert something inside square brackets then replace that with some other content; it could be a simple sentence or it could be a massive PHP function, it all depends on what you instructed WordPress to do.

The shortcode API allows you to create your own shortcodes by adding functions to your theme functions.php template (this is located at www.yourwebsite.com/wp-content/themes/yourtheme/).

In addition to creating your own shortcodes, WordPress also includes five default shortcodes with the WordPress core:
audio – Allows you to embed audio files.
caption – Allows you to wrap captions around content. It is commonly used with images.
embed – Allows you to embed a wide range of content such as video, audio and tweets.
gallery – Allows you to insert image galleries.
video – Allows you to embed video files.

In this article we will create some simple WordPress shortcodes to help you create any functionality you like.

A Basic Example

In our first example we want to create a shortcode that will create some “custom text” every time we type [spin2win] into the editor. First we need to create the callback function that will return the “custom text”

function spin2win_func() {
return “I am new shortcode text”;
}

Next we need to add this shortcode to WordPress using the add_shortcode function in either our functions.php file

add_shortcode( ‘spin2win’, ‘spin2win_func’ );

So the full code would be like this :

function spin2win_func() {
return “I am new shortcode text”;
}
add_shortcode( ‘spin2win’, ‘spin2win_func’ );

Note : spin2win_func and spin2win can be any name.

Creating a Shortcode With Attributes

Attributes can expand the functionality of shortcodes by allowing you to pass data through your shortcodes.

When WordPress encounters this we want a function that will insert an image. It needs to read the width and height attributes

function get_images($atts) {
extract(shortcode_atts(array(
‘width’ => 250,
‘height’ => 180,
), $atts));
return ‘‘;
}

add_shortcode(‘getpics’, ‘get_images’);

That’s all 🙂

Magento 500 internal server error

Magento 500 internal server error

A 500 Internal Server Error in Magento can be frustrating, as it disrupts your store’s functionality and can impact sales.

This error often stems from incorrect file permissions, memory limits, corrupted .htaccess files, or issues with third-party extensions. To resolve it, start by checking the error logs (var/log and var/report) for specific details.

Ensure that the correct file permissions are set (755 for directories and 644 for files), and try increasing the PHP memory limit in the php.ini file. Additionally, clearing the Magento cache (bin/magento cache:clean) and regenerating static files (bin/magento setup:static-content:deploy) can help. If the problem persists, disabling recently installed extensions and verifying server configurations, such as the .htaccess file, may pinpoint the issue.

A well-maintained Magento installation with up-to-date software and optimized server settings can prevent such errors from recurring.

Media query for large screen

Media query for large screen:

@media screen and (min-width: 1400px) {

}
@media screen and (min-width: 1600px) {

}
@media screen and (min-width: 1900px) {

}

Settings defined in website scopes are ignored in magento2

Today I will show you how you can fix the Settings defined in website scopes are ignored.

This is a core bug in 2.1.3 – https://github.com/magento/magento2/issues/7943

The change you need to make is to vendor/magento/module-store/Model/Config/Processor/Fallback.php

Change this

/**
* Retrieve Website Config
*
* @param array $websites
* @param int $id
* @return array
*/
private function getWebsiteConfig(array $websites, $id)
{
foreach ($this->websiteData as $website) {
if ($website[‘website_id’] == $id) {
$code = $website[‘website_id’];
return isset($websites[$code]) ? $websites[$code] : [];
}
}
return [];
}
To

/**
* Retrieve Website Config
*
* @param array $websites
* @param int $id
* @return array
*/
private function getWebsiteConfig(array $websites, $id)
{
foreach ($this->websiteData as $website) {
if ($website[‘website_id’] == $id) {
$code = $website[‘code’];
return isset($websites[$code]) ? $websites[$code] : [];
}
}
return [];
}

Note the line

$code = $website[‘code’];

Redmi mobile suddenly not starting

Some people like me may get the issue of Redmi mobiles suddenly switched off and not booting. That’s really very irritating. In the mobile age I think no one can live without…. 🙂

So I tried to find the issue. First I tried to use another charger and no luck!! Whole day my mobile was switched off. I was thinking what Can I do… So I tried to connect mobile to my Laptop… but still no luck. That was not charging and not starting… I worried may be I have to go to Redmi customer service but once again I google on about this issue and find many tricks as I have applied above but no works.

Finally I found a solution and that worked for me, then I thought I have to write that on my blog.. May be this trick will work for other people…

Push Vol down and power for around 15 second, It will show MI BUNNY fastboot mode and press till vibrate!!

That’s it.

PS : The issue caused due to app/system hang.