How to replace Paragraph Break with Line Break in LibreOffice Writer

In Microsoft Word, this is very easy. You just need to open “Find and Replace”, enable Wildcards and replace ^13 (paragraph break) with ^l (line break).

But this is a little different in LibreOffice Writer. But you do not require any macro for this. Just follow this process.

  • First of all, type a line break by pressing “Shift” + “Enter”
  • Now copy this line break
  • Now open “Find and Replace” (You can use the shortcut “ctrl” + “H” to open “Find and Replace” dialogue box)
  • Click on checkbox for Regular Expressions
  • Type “$” in the find box to search for paragraph break
  • Click on “Find All”. This will cause all the paragraph breaks in the document to get selected
  • Close the “Find and Replace” box without removing the selection
  • Press “ctrl” + “V” and it will paste line break in place of all the paragraph breaks

That’s it.


Whitelist all sub-sites for wp_safe_redirect in WordPress Multisite

In WordPress, there are two functions for redirecting a page- wp_redirect and wp_safe_redirect.

wp_redirect can be used to redirect to any url.

wp_safe_redirect can only redirect to current site. In case any external url is provided, the page is redirected to wp-admin.

For security, it is recommended to use wp_safe_redirect function for any redirects. This works fine for single WordPress installation. But in case of subdomain based WordPress multisite, this fails because each sub-domain is an individual domain for wp_safe_redirect.

What if we want to use wp_safe_redirect to redirect our pages only within network and not outside?

For this purpose, WordPress has a filter to add additional domains to the wp_safe_redirect whitelist. You can add any domain or sub-domain, internal or external, through this method.

In this article, we will focus on how to whitelist all the sub-domains of a network.

Just add the following code to your custom plugin or child theme’s function.php file.

// Filter to add all subdomains to wp_safe_redirect whitelist
add_filter( 'allowed_redirect_hosts', 'whitelist_all_subdomains' );

function whitelist_all_subdomains( $hosts ) {
    $sites = get_sites();
    $domains = array();

    foreach ( $sites as $site ) {
        $domains[] = $site->domain;

    return array_merge( $hosts, $domains );

This code gets all the sites through get_sites function and iterates all the sites to create an array of all domains/sub-domains of sub-sites. It then adds that to the whitelist.

If you try now, you will see that page redirects across sub-sites of a network using "wp_safe_redirect" are flawless.


Make Javascript sequential with “async” and “await”

Most of the older programming languages are sequential in nature. That means, when the code runs, it is executed line by line. If there is a function call, the next line is executed only when the function has been executed and returned control. This is blocking in nature and helps programmers easily predict the output of their code.

But when we move to async languages like Javascript, code is non-blocking in nature. That means, execution does not wait for any function to return response. This is good for performance, but creates a problem when the next line of code requires output from the function call made in previous line.

To solve this problem, Javascript provides Promises. Promises allow us to write a callback function to process the response of the called function. But their syntax requires to write another function to handle the response. Also, if there are multiple functions, it may lead to callback hell.

The syntax of a function returning a promise is:

function add(a, b) {
    return new Promise(function(resolve, reject) {

And this is how we handle the returned Promise:

add(2,3).then(function(response) {

This becomes cumbersome if there are a lot of function calls nested inside one another. To simplify this code, there are two keywords in Javascript to write promises in a very simple way- async and await.


async can be placed before a function definition. It means that the function will always return a promise. If the returned value is not a promise, it will wrap it in a promise and return.

async function demoFunction() {
    return 1;


await can be placed before any line of code to ensure that Javascript hold the execution till that line is executed. If there is a function call in that line, Javascript is wait till the function returns a response.

async function demoFunction() {
    let sum = await add(a, b);

In the above example, we are calling a function called add and saving its value in a variable called sum. The await ensures that the next line is executed only after we get the value returned from the function add. If we remove the await keyword from this, console.log may print an empty variable.

So, even if the called function is returning a promise, there is no need of defining any callback function. Just simply store its return value in a variable and process it in the next line of code. This is pretty much like we do stuff in C or PHP.

Note: await can only be used inside an async function.

This is such a simple syntax that can easily make Javascript code sequential whenever needed.

To read the detailed description of these keywords, you can refer to the following articles:


Javascript: Loop over querySelectorAll without error

In Javascript, there are a lot of instances when you want to find multiple elements on a page to apply a common operation to all of them.

Suppose you want to hide elements of a particular class present on your web page. To do this, first get an array of all such elements using querySelectorAll and then loop through that array items to change the display property of all such elements.

But there is an issue. querySelectorAll also returns additional data, a static NodeList. If you iterate through all the items, you will hit the static NodeList which will give error.

So, what is the solution for this?

First, find the number of elements found matching the given selector using length property. Then use a for loop and iterate upto length number of items.

This will be more clear through following code example.

// Let's assume that we are looking for all elements with class "demo-item"
elements = document.querySelectorAll( '.demo-item' );
var i = 0;
for ( i = 0; i < elements.length; i++ ) {
elements[i].style.display = "none";

Hope this helps.


Where to add custom code in WordPress

WordPress offers a lot of features right out of the box. If you want to create a blog, you can start using WordPress without the need to add any additional plugin.

When you want some additional functionality not provided by the core WordPress, you can find and install a plugin from the WordPress plugin repository.

WordPress plugins repository contains thousands of plugins and in most cases, you will find the plugin for your required functionality.

But there are cases when you do not find the perfect plugin. There may be plugins, but they are so bloated that you do not want to use them. Or, you need a very small functionality and installing a full-blown plugin with a lot of unnecessary features may seem illogical.

In such cases, it is always better to write your own code for adding that functionality. But where to add that code?

Where to add the code

If you want to modify a core WordPress feature, you may be tempted to edit the WordPress core files directly. But this is not a sustainable practice as whenever WordPress will be updated, your changes would be overwritten.

If you want to change the functionality of your current theme, you edit the functions.php file inside your theme. But again, if the theme is updated, you will lose the changes.

In short, you must NOT edit any core WordPress files, themes or plugins. Rather, you need to add code to override or extend that functionality based on the APIs provided by WordPress.

There are two recommended ways to add custom code to WordPress-

  • Create a child theme of your current theme and add code to its functions.php file
  • Create a custom plugin and add it to your website

Theme vs Plugin

WordPress has very nicely separated the design and development functionality. Themes are meant for the front-end design of the website and plugins are meant for adding functionality to the website.

It is important to strictly follow this separation logic to ensure a clean and easy to maintain code.

WordPress provides the functionality to add a child theme to override the current theme’s files. You can override templates and add code to functions.php file.

But you must not add any code to a theme that is not related to front-end design. All such code should reside in plugin only. Plugins are the right place for all your non-design functionality.

I have seen a lot of WordPress tutorials on various popular websites that encourage users to add custom code to their child theme’s functions.php file. But this approach is wrong.

If you add your custom code to WordPress child theme, you violate the code separation logic, thus messing up your website for the future.

Creating a small single-page plugin and adding it to WordPress is easier compared to adding a child theme. Plugins are easy to manage and you can easily create a directory structure for your code if you are creating a complex plugin with multiple functions.

Is it safe to add custom code to my WordPress blog

Security is a very important concern when writing code. If you are not a good programmer and somehow you leave any vulnerability in your code, it can be a huge issue for your website. To make sure that this does not happen, you should follow proper coding standards and best practices.

If it is a small function, it is very easy to ensure that it is free from vulnerabilities. But in case you are planning for a complex plugin, make sure that you properly review your code and test the code for all possible scenarios.

If you are a decent programmer, you can write code which is secure and clean. Though security is important, fear of security must not discourage you from creating your own plugin. It actually enhances your skill and gradually you become good at it.

Just carefully write your code, review it properly and test it thoroughly. You can refer to security best practices for coding, you can review the code of plugins offering similar functionality or if needed, you can take an online course to improve your programming skills.

It is not reinventing the wheel

A lot of people tell you not to write your plugins if someone has already created a plugin with your required functionality as you will be reinventing the wheel.

This logic does not work efficiently in the coding world. Yes, creating an entire CMS like WordPress to host your blog is surely reinventing the wheel. But, adding some code to add functionality may not be the same.

If you are writing code to avoid installing a badly coded or bloated plugin to your WordPress blog, it is a good practice.

If you write a good plugin which works nicely for your WordPress blog and you think that it will be beneficial for a lot of WordPress users, you may decide to release the code publicly by submitting it to WordPress plugin repository.

This way, you can contribute back to the WordPress community and at the same time, it will help you improve your coding skills.


WordPress may be full of a lot of functionality, there may still be many things where it may fall short of your expectations. Though a lot of plugins are available in the WordPress plugin repository, you may not find the plugin which suits your requirements. This calls for writing your custom code and add it to your WordPress blog.

Writing custom code for WordPress may be easy, but you should carefully add your code at the correct place to keep it clean and easily maintainable.

The best way to add your custom code to WordPress is to create a plugin and add it to your WordPress blog.

Do make sure that you follow proper coding standards and best practices. Also, do proper code review and testing to ensure that your code is safe.


How to create a WordPress plugin

In this post, you will learn how to create a simple WordPress plugin without any complex setup or need of FTP/SSH to your hosting server.

Before we begin with this post, let us understand a few things.

I will try to keep the code as simple as possible. My objective in this post is to help you understand how easy it is to create WordPress plugins.

You do not need any FTP or SSH access to your hosting server. All you need is access to your WordPress dashboard with an administrator account with the ability to upload new plugins.

No tools setup is required for creating this plugin. You can write the code in a basic text editor like Notepad which is already included in your Windows computer.

However, I would recommend using a slightly better text editor like Notepad++ which also offers syntax highlighting, but it is completely optional.

No FTP tool is required to upload the code. If you have one and know how to upload, you can try that, but it is not needed at all.

WordPress is amazing

WordPress offers amazing features right out of the box. If you want to create a blog using WordPress, it is as easy as installing software on your Windows computer. There is no coding required.

WordPress makes it so simple. It is a complete blogging system with everything in place to write your next awesome blog.

Let us take a look at some of the basic features of WordPress supported out of the box-

  • Create posts, classify them with categories and tags
  • Upload and manage images, videos, etc. using its built-in media library
  • Define the URL structure of your choice using permalink settings
  • A simple yet fully functional comment system with dedicated comment management dashboard
  • Thousands of free themes to change your blog’s appearance with just a single click
  • Thousands of free plugins to add any additional functionality

There are many more features that I cannot list here, but you got the idea. WordPress is a complete powerhouse for bloggers helping them focus on their content rather than worrying about managing the technicalities.

Why plugins

No matter how comprehensive a particular software is, there may be innumerable cases where some additional functionality is required. The same is the case with WordPress. Though most of the blogging features are included in the core, there may be situations where additional functionality is needed. That’s where WordPress plugins come into the picture.

For example, if you need to add your copyright text in the page footer, you can find and install a plugin that offers that functionality. The plugin may also add settings page to your WordPress dashboard to allow you to configure the plugin settings.

But, what if the plugin you found includes 10 more features which you do not need. Though it will work for you, it will add bloated code to your blog by adding unnecessary additional features which are of no use to you.

In such a scenario, a good option can be to create your plugin. Yes, it is very easy and a much better option if you want to add a small functionality to your WordPress blog.

Before we dive into creating the plugin, there is one thing you need to know- WordPress Hooks.

What are WordPress Hooks

As the name suggests, hooks are small checkpoints within the WordPress code where you can inject your functionality. You can just write a function and connect to the hook and your function will be called every time the hook is executed by WordPress.

For example, WordPress defines a hook called wp_footer‘ which is called by WordPress when it renders the page footer. You can connect your code with this hook to print your copyright notice in the footer.

Hooks are of two types-

  1. Action hooks
  2. Filter hooks

Action Hooks

Action hooks are mainly for executing some code and print it. For example, I already told you about wp_footer. It is called during the creation of page footer during page load and you can print anything you want to the footer by hooking your function to this action hook.

You can also use an action hook to execute some code that has to be executed on each page load. For example, wp_init is an action hook that is executed when WordPress loads the required data before rendering the page. You can hook into this to execute anything you need before the page is sent back to the user.

All you have to do is create a function and tell WordPress to call it whenever wp_footer is executed.

Filter Hooks

Filter hooks are useful if you want to manipulate or modify data within the WordPress functions. For example, the_content is a filter hook that filters the post content to be printed in the post or page. You can hook into this filter, and it will pass the content string to your function. You can modify this value and return the new value which will be taken by WordPress to print the final content on the page.

This understanding is enough to create your first plugin. I will discuss the code in the next section.

The Plugin

We have got a good understanding of WordPress hooks. Now, using this knowledge, we will create a small plugin. To keep things simple, our plugin will simply add some text to the footer of our WordPress blog.

A WordPress plugin can be a single file or it can be a directory with a bunch of files. To keep things simple, our current plugin will be of a single page, with all the code in the same file.

First of all, we need to select a unique name for our plugin file which must not be a clash with the name of any other plugin in the WordPress repository. To ensure that there is no clash, we will prefix our plugin name with our blog’s name. A good file name can be webrosis-footer-printer.php.

You can use the prefix of your name, blog or company. The file name is completely your choice.

Create a file with this name and open it in a text editor.

Every WordPress plugin index file (in case of a directory) or main file (in case of a single-page plugin) must contain header comment with specific header fields as defined by WordPress.

WordPress uses the details provided in this header comment to display plugin’s information in the installed plugins list in the WordPress dashboard.

In the header comment, it is mandatory to define "Plugin name". Everything else is completely optional. As an example, below is a header comment which I have created for our plugin. You can replace the values with your own.

 * Plugin Name:       Webrosis Footer Printer
 * Description:       Prints custom content in footer
 * Version:           1.0
 * Author:            Abhineet Mittal

There can be more header fields, but for now, this seems enough for our plugin.

The Code

We want to print our custom content to page footer. So, we will hook into ‘wp_footer’ action hook.

We will first write a function to print our custom content and then hook it to wp_footer action through `add_action’ function.

// Function to print copyright notice in footer
function webrosis_print_content_in_footer() {
    echo 'The content on this website is copyright protected. Do not copy. All Rights Reserved.';
// Now hook this function to wp_footer action
add_action( 'wp_footer', 'webrosis_print_content_in_footer' );

Save the file.

That’s it. This is the only code you need to write. When added to your WordPress blog, this plugin will print the given content in the page footer.

Here is the complete code-

 * Plugin Name:       Webrosis Footer Printer
 * Description:       Prints custom content in footer
 * Version:           1.0
 * Author:            Abhineet Mittal

// Function to print copyright notice in footer
function webrosis_print_content_in_footer() {
    echo 'The content on this website is copyright protected. Do not copy. All Rights Reserved.';
// Now hook this function to wp_footer action
add_action( 'wp_footer', 'webrosis_print_content_in_footer' );

This plugin will not add any configuration settings to your WordPress dashboard as we have not coded that. However, once you start writing plugins, you can learn about the WordPress Settings API to add your custom settings page in the WordPress admin dashboard.


You have created your first plugin. Now its time to add it to your WordPress blog. Use the following steps-

  1. Zip this plugin file
  2. Go to your WordPress blog dashboard and click on "Plugins > Add New"
  3. Upload the zipped file of your plugin
  4. Now activate the plugin by clicking on "Activate"

If you have done everything till now exactly as I told you, the plugin will be successfully activated.

Now go to any post or page on your blog frontend and you will find that your content has been added to the footer.

Congratulations! You have successfully created your first WordPress plugin.

So, you saw how amazingly simple it is to create a WordPress plugin. If you want to add small functionalities, it is better to write your small functions and add them to your plugin.

Your plugin can only be installed by uploading the zipped file. It will not be available in the WordPress plugins repository until you submit it.

I have not covered uploading the plugin in the WordPress repository as it is a separate process and requires many more steps. At this level, you must first practice writing plugins. Once you start writing useful plugins, you may consider submitting them to the WordPress plugins repository to be used by the community.

Way forward

In this post, you have learned how to create a WordPress plugin. But our example was a very simple one as it was just to explain to you how a plugin works.

To create more meaningful plugins, you can read about other filters and API functions provided by WordPress. A good starting point is WordPress Documentation.

Here are a few simple ideas which you can implement in your plugin-

  • Add Google Analytics code by hooking into wp_head action
  • Add beautiful author box below the content of your posts by hooking into the_content filter
  • Modify the title of your pages by hooking into ‘wp_title’ filter

You can think of many more ideas as per your blogging requirements.


We created a very simple WordPress plugin that printed some custom content in our blog’s footer. It showed, how easy it is to add small functionalities to your WordPress blog by adding simple code in the form of plugins.

Thanks for reading. I hope you found this post useful.

Web Development

How to use PHP built-in web server

If you are a PHP developer, chances are you have already set up a web server (WAMP or LAMP software) on your desktop. It gives you the ability to test your PHP code locally rather than testing it on a remote server.

But what if you are working on a machine where you do not have a web server installed? Or, you may not have sufficient permissions to install the webserver on a desktop.

Luckily, PHP provides a way out of this situation. PHP has a built-in web server that can be run directly without the need for any setup or installation.

Some assumptions

For this tutorial, I am making the following assumptions-

  1. My first assumption is that you are on a Windows machine, but you can implement this on any system by downloading appropriate PHP files.
  2. My second assumption is that your website is in the following folder in your desktop- F:projectsmy-php-website. You may change it to the appropriate folder of your website.
  3. My third assumption is that there is a valid index.php file in your website root folder

How to run the PHP built-in web server

  1. Download PHP for Windows.
  2. Unzip it and save it on your desktop- F:projectsmy-php-websitephp
  3. Now press, type cmd, and press enter, to open your command prompt
  4. Now navigate to your website’s root folder using this command- cd f:projectsmy-php-website
  5. Now execute this command to run the webserver pathtophpphp.exe -S localhost:4000

It will immediately fire up the PHP web server. You can type localhost:4000 in your web browser and it will run your index file.

That’s great! Such a convenience without the hassles of setting up an entire web server. You can run any number of instances of this server. It is single-threaded and has its limitations, but it is sufficient for running the PHP website test code.

You can also make changes to the PHP configuration by editing the php.ini file. You can also add/remove PHP modules.

URL Rewriting and routing

There is one important feature missing in PHP built-in server- URL Rewriting. Suppose you have URL rewriting for pretty permalinks enabled in your website and you want to test that functionality locally.

Apache webserver provides the capability to add the .htaccess file to implement URL rewriting. In the PHP server, you can implement similar functionality by setting up a router.php file.

Add a router.php file to your website root and add the following code-

// router.php

// Get the url path and trim leading slash
$url_path = trim( $_SERVER[ 'REQUEST_URI' ], '/' );

// If url_path is empty, it is root, so call index.html
if ( ! $url_path ) {
    include( 'index.html' );

// If url_path has no dot, it is a post permalink, so add .html extension
if( ! preg_match( '/[.]/', $url_path ) ) {
    include( $url_path . '.html' );

This code takes the path from URL and rewrites requests for HTML files to call them without .html extension. You can implement any functionality you want.

Do remember, adding router.php will give the responsibility of adding the entire response on your shoulders. So, if you are including static files like style files with .css extension, you will have to handle that as well.

// Get the url path and trim leading slash
$url_path = trim( $_SERVER[ 'REQUEST_URI' ], '/' );

// In case of css files, add the appropriate header
if( preg_match( '/[.css]/', $url_path ) ) {
    header("Content-type: text/css");
    include( $url_path );
    // You can do the same for other file types as well

Now, go to the command line. If your PHP server is already running, press ctrl+c to stop it. Run this command-
pathtophp.exe -S localhost:4000 router.php
Now, again open the localhost:4000 in your web browser. It will now execute your router.php file and which, in turn, will include the required PHP files.

This technique will save you time if you quickly need to check your code.

Limitations of PHP built-in server

PHP built-in server is a useful tool for developers. However, it has its limitations.

  1. It is single-threaded. That means if a request is blocked, the server will stall the execution.
  2. Once you start adding more logic to your router.php file, it will soon become cluttered. It is very difficult to scale it for large projects.
  3. There is no SQL support. You can either use SQLite, which is a good option or install a separate SQL server.


Despite its limitations, PHP built-in web server is a useful tool for web developers. It helps in saving time in many situations and makes code testing, an easy task.


Enable Gzip compression in WordPress with htaccess

With the advancement of web technologies, you have ready-to-use frameworks for any functionality you want to add to your website or WordPress blog. Just include these framework files to your website and add its features through their easy to use API.

For example, if you want readymade styling for your website, you can use CSS frameworks like Bootstrap or Foundation. Similarly, a lot of Javascript libraries are available to add advanced features to your website, without needing you to code complex functions.

Using these frameworks, developers can create fully functional websites in a short time. All they have to do is to include the framework files to their HTML page, then use its functions to implement the desired functionality.

Similarly, these days, people are more oriented towards visual data. It has become necessary to add a lot of images and videos to their content to attract and engage users. Many times, they also include custom-developed CSS and JS files in addition to all the other resources.

Though this makes the websites better in terms of functionality and aesthetics, adding all these files makes the webpage very heavy and negatively affects the website performance.

In a lot of WordPress themes, each page load requires dozens of additional scripting and styling files in addition to the already included media files.

When a user opens such a website in their browser, the browser immediately starts downloading all the resources from the requested web page and render it for the user. It may include stylesheets, script files, images, videos, etc.

Each request to such files increases the page load time as the user has to wait for the resources to get downloaded. If you have multiple files with huge sizes, it adversely affects your site performance.

Now, if the user is on a high-speed internet connection, this may not be a problem at all. But, you cannot assume that all your users are accessing your website through the best internet connections.

As a simple WordPress user, you may have downloaded or purchased an excellent theme for your blog. You may like the functionality of that theme, but the extra file requests are slowing down your website.

You may not know how to optimize the theme through coding. But, you can optimize your blog for better performance through some simple tweaks at the server level.

Two things can be done to improve your WordPress blog performance. They are browser caching and Gzip compression. You can do this at the server level by simply adding some configuration code to .htaccess file in your website root folder.

Browser Caching ensures that your static resources are cached by the user browser to avoid multiple requests of the same file on different pages. The user will save on bandwidth, and the site load speed will improve.

I have already written a post about Browser Caching where I have provided the required configuration.

Let’s take a look at Gzip compression in this post. Gzip compression speeds up your WordPress website by compressing the resources at the server level using simple .htaccess configuration in Apache server.

Gzip compresses the files to reduce payload. It even compresses the minified CSS and JS files to smaller sizes.

Just add the following code to your .htaccess file.

# BEGIN Compressing

# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml

# END Compressing

This code ensures that Apache will compress all the files using Gzip before sending them to the user.

Once you implement this code, check your page speed using Google Page Speed Insights tool. You will notice the improvement in your page speed score.

Even if you are not facing website speed issues, you must implement Browser Caching and Gzip Compression on your website. It is recommended by Google & widely supported by most browsers.


Correct file permissions for WordPress on Apache

File permission is a simple yet complex issue. If you manage a website, you need to ensure that the file permissions are adequate so as to allow users to perform operations on the file and at the same time, you need to ensure that file permissions are strict enough to prevent security and hacking incidents.

Wrong permissions will break your automatic updates. Also, if you run composer, you may struggle as composer should not be run as root or sudo user, and non-root user would need read/write permissions to run composer.

This situation usually arises when you run a website on a self-managed server like the one provided by DigitalOcean or Amazon AWS Lightsail. However, the permissions are equally valid for managed or shared hosting where the host has provided you the SSH access to your files.

In this article, I have provided simple file permissions for your WordPress website hosted on Apache server. These permissions should be sufficient for most of your websites, including those which are not built on WordPress.

Giving the correct file permissions to your WordPress website

To begin with, Apache server runs all the processes requires to read/write the website files & directories. So, we need to provide the ownership of the website files & directories to Apache. As Apache runs as www-data, following command is appropriate to give ownership of your entire website folder to www-data user and group.

In your SSH terminal, run the following command.

sudo chown -R www-data:www-data /var/www/wordpress

Here, I am assuming that your wordpress website root is /var/www/wordpress. You can change it to the directory in which your website is hosted.

Now, we need to give all file permissions (read, write, execute) to owner (Apache server) because server needs to perform read/write operations on files & directories. It will ensure that our website runs smoothly without error.

Giving read/write permissions to www-data is fine for your website to run and auto-update without any errors. But, if you try to SSH into your server as a non-root user, you will not be able to read/write your files inside the wordpress directory.

Also, if you use composer, you need read/write access to website files. As per composer’s official documentation, it is recommended that you should NOT run composer as root or sudo user. You should run composer as non-root user. Same is true for other utilities as well which require read/write permissions in your wordpress directory. This means we need more permissions.

For this, I am assuming you have already created a new user with sudo privileges and have logged in through that sudo user (not root use).

First, add you to the www-data group using the following simple command in your SSH terminal. Remember, you must be logged in as a non-root user, with sudo privileges, as whom you want to run composer.

sudo adduser $USER www-data

Above command adds you to www-data group.

Now give read/write/execute permissions to all the files and folders to both owner and group.

sudo find /var/www/wordpress -type d -exec chmod 770 {} ;
sudo find /var/www/wordpress -type f -exec chmod 660 {} ;

Update: Recently I was facing following error while running these commands-

`find: missing argument to -exec'

I fixed that by adding a slash before the terminating semicolon.

So, the update commands are-

sudo find /var/www/wordpress -type d -exec chmod 770 {} \;
sudo find /var/www/wordpress -type f -exec chmod 660 {} \;

You need to log out and log in again for the new permissions to take effect.

That’s it. You now have the correct permissions.

How to check if your WordPress website has correct file permissions

After setting up file permissions, you must validate the new file permissions. To check this, try the following two things-

  • Run composer and check if there is any permission error.
  • Try uploading a file in the WordPress media library.

If you are able to execute the above two operations successfully without error, your WordPress website has the correct file permissions.

Web Development

Customize your link preview on Facebook

When you share a link to your post on Facebook or Twitter, it automatically generates a preview card with a title, description, and optional image. This preview helps your post visibility by presenting it in an attractive manner to other users.

This preview can be customized for all our pages using Open Graph Protocol (OGP) created by Facebook. Twitter supports this protocol adding a few tags of its own as well. In this post, I will discuss the required meta tags to customize your link preview.

In this article, based on the Open Graph Protocol, I will tell you the exact tags to be added in the head section of your blog. This will transform your posts into rich social objects on Facebook, Twitter etc.

What is Open Graph Protocol

Open Graph Protocol is a schema to assign properties to a web page which can be easily understood by the compliant applications. Open Graph Protocol is implemented through meta tags in the head section of HTML web page and is loosely based on other existing schema technologies.

Open Graph Protocol provides different meta tags to be added to your page to customize the different elements of a web page as well as to define a lot of other properties for that page.

Though we can add all the tags defined in the Open Graph Protocol for a webpage or blog post, it will be redundant and will add to extra code. So, in this post, we will look at the basic required meta tags which will be sufficient for your customized link previews on Facebook & Twitter.

Customizing a link preview

If you look at your link preview of a post you shared on Facebook or Twitter, you will observe that there are three important elements-

  • Title
  • Short Description
  • Image

These are the visible elements which are needed in a link preview. Apart from these, there are two more properties, which are type and url.

Type defines the type of web page. For blog posts and news articles, it is ‘article’. Url is the canonical url of the object. This acts as a unique id for the object in the entire graph. In case of multiple pages sharing same data like comment pages on a blog post, this url remains same.

Apart from this, Facebook requires you to add their FB App ID in another meta tag. As described in my previous post on the topic Social Sharing Buttons, you can easily get your Facebook app id from your Facebook for Developers dashboard.

In case of Twitter, though it defines it’s own tags, it officially supports the Open Graph Protocol as well. So, if you add separate Twitter meta tags along with Open Graph tags, Twitter tags will be redundant. So, in the interest of keeping our code concise, we will only add those Twitter tags, which are not covered by Open Graph Protocol.

Twitter only requires one extra meta tag, ‘twitter:card’, which we will add in our code.

Let’s take a look at the final code.

<meta property="og:type" content="article" />
<meta property="og:title" content="Title of your page">
<meta property="og:description" content="Description of your page">
<meta property="og:image" content="Image/url/of/your/post's/featured/image">
<meta property="og:url" content="Canonical/url/to/your/page">
<meta property="fb:app_id" content="Your_FB_App_ID" />
<meta property="twitter:card" content="summary_large_image">

You can see that "og:type" and "twitter:card" tags are static and will remain the same for all blog posts. "fb:app_id" will also remain the same if you are using same app id for entire website.

You will have to modify four tags as per your post data- "og:title", "og:description", "og:image", "og:url".

Paste these tags in the head section of your HTML page. Your page is now rich social object.

Sometimes Facebook or Twitter fetches wrong values for these tags, or sometime they may not even able to fetch any data. Also, you may have changed the post title, description or image after the page has been fetched by Facebook/Twitter. As Facebook & Twitter cache their data for many days, you may not be able to see the updated data when you share that link.

In such cases, you may use the Facebook Sharing Debugger which shows how Facebook looks at the Open Graph Meta of your page and shows you the open graph data currently saved by Facebook for your post. It also allows you to force Facebook to fetch the data again, in case, there is a discrepancy.

What happens when there are no Open Graph meta tags on your page

If there are no Open Graph meta tags on a page, Facebook tries to get that data automatically based on page content. Usually, the title of the page is taken as title. Description is taken from the description meta tag, if available. Otherwise, it takes first few lines from the content. Similarly, the first image found on the page which is larger than 200×200 pixels id taken as image.

There is no confirmation that in the absence of Open Graph meta tags, Facebook will take only these values. It can take any value as defined by their fetching algorithms. So, to avoid this uncertainty, it is always advised to add the above seven meta tags to all your web pages.


So, you can see that Facebook’s Open Graph Protocol is currently kind of a universal protocol to define social properties of a web page. It is supported by Twitter and many other social networks.

It is very easy to implement as it requires adding only seven basic tags. You can add many more tags by referring to the Open Graph Protocol Documentation.

So, don’t wait anymore. If you have not yet implemented the Open Graph meta tags in your blog or website, it is important that you do it now.

Web Development

JSON-LD: Add Structured Data to improve SEO

Adding structured data like JSON-LD to your blog or website is a very important search engine optimization (SEO) technique. It helps Google to understand your content better and helps your website to get a better search ranking.

What is Structured Data

Structured data is a standard format to add information to a page which can be easily understood by search engines to identify the content of the page. For example, if you have a cooking blog, Google needs to understand if a particular page is for recipe and if yes, it needs to extract key information from that page to match with the user query. Structured data helps Google by directly providing this information.

Structured data is comprised of predefined properties which are based on

There are multiple formats to add structured data to your website. The three most popular formats which are supported by Google are-

    This is a subset of JSON where all the properties are defined in the head section of an HTML page.

  • Microdata
    In the Microdata format, structured data properties are nested within HTML content by using HTML tag attributes.

  • RDFa
    Similar to Microdata, RDFa uses HTML tag attributes which are officially HTML5 extension.

Out of these three, Google recommends using JSON-LD for structured data whenever possible.

So, our focus in this post will be only on JSON-LD. There is no use to add multiple structured data formats. One structured data format implemented efficiently is enough for Google to understand the key information provided by our content.

JSON-LD is the easiest to implement among all other structured data formats as it is consolidated at a single place in the head section. Also, the JSON structure is easy to create either manually or through programming making it very fast to implement. The cluttered approach of Microdata & RDFa is something which actually results in errors in implementing structured data. JSON-LD is free from all that mess.

The content on internet is mainly written in the form of blogs containing a lot of blog posts. So, in this article, I will tell you how to implement JSON-LD for a blog post.

Though, provides a large number of properties for each page type, it is not necessary for you to implement all those properties. A few important ones are enough.

Implementation of JSON-LD in a Blog Post

First of all, let’s take a look at the complete JSON-LD snippet to be added to the head section of a blog post. Then, I will explain each property. Most of the properties are self explanatory.

<script type="application/ld+json">
  "@context": "",
  "@type": "BlogPosting",
  "headline": "Enable browser caching on Apache server using htaccess",
  "description": "Browser caching for all types of files can be easily done using Apache's .htaccess file. This simple configuration results in a faster website, less consumption of bandwidth and better user experience.",
  "mainEntityOfPage": "",
  "image": "",
  "datePublished": "2019-08-06",
  "dateModified": "2019-08-06",
  "author": {
    "@type": "Person",
    "name": "Abhineet Mittal",
    "description": "Abhineet is IIM Alumnus and Founder of popular Digital Publishing Platform, Sahityapedia. He is a technology enthusiast by hobby &amp; an avid reader.",
    "image": "",
    "url": ""
  "publisher": {
    "@type": "Organization",
    "name": "",
    "logo": {
      "@type": "ImageObject",
      "url": ""

In this code, I have taken JSON-LD from one of the blog posts of this blog. Let’s discuss each element used in this code.

  • The entire JSON-LD snippet has to be wrapped inside <script type="application/ld+json"> and </script> tags.
  • @context is standard and should be used as-is.
  • The most relevant type for a blog post in is BlogPosting. So, we will use that for @type.
  • Headline is the page title. This title will be visible on the Google search results page.
  • Description is a short summary of the page, and like Heading, it will be visible on the Google search results page.
  • mainEntityOfPage defines that the topic discussed is the primary topic for this page. That means it has to have canonical URL.
  • Image is URL to featured post or thumbnail of this post.
  • datePublished & dateModified are self-explanatory.
  • Author adds nested properties to define a Person. Add your name, description (biography), image and URL.
  • Finally, Publisher is similar to Author, but it indicates an organization and must have name and logo properties.

Interestingly, according to, Publisher can be either Person or Organization. But Google only accepts Organization as a Publisher. So, do not use Person there.

Finally, you can validate your schema using Google Structured Data Testing Tool. If you see any error, try to fix it based on the comments provided by Google.

And that’s it. Your blog posts are now SEO ready which can be easily understood by Google.

Make sure you do not stuff structured data with unrelated content. Structured data should clearly describe the actual content in the blog post. Doing otherwise, will hurt your search ranking as Google’s algorithm’s are smart enough to notice any discrepancies.

When all this is done, wait for a few days and observe the change in your search rankings. Properly implemented structured data will definitely boost the search ranking of your blog bringing in more traffic.

Web Development

Social Sharing Buttons without Javascript

If you are developing a website, it is imperative to have social sharing buttons to increase social engagement which in turn will result in higher traffic. A lot of widgets are available for this purpose.

The Pros

Adding a single line of Javascript adds all the popular sharing buttons to your website. Some services allow you to customize them through remote dashboards. They also add share count and other metrics to your buttons.

From button styling to icons, everything is handled by these widgets. All you have to do is select which buttons to show and style of those buttons.

These services also provide cloud-hosted analytics data where you can easily monitor the visitor and their sharing pattern of different posts.

The Cons

When you add these widgets, they simply add the Javascript SDKs of these social websites which load the sharing button and other metrics like the number of shares, likes, etc. along with the buttons.

This may seem good, but it adds a lot of processing to the webpage. This results in higher load time and thus, lower ranking in search engine result pages (SERP).

A major portion of your added analytics becomes redundant if you already have Google Analytics code installed on your website. Social analytics can also be implemented through events in Google Analytics, thus making additional tracking redundant. In most cases, social analytics added by these sharing buttons adds little value.

Also, many of these services, track your visitors and you have no option to opt-out of it. They get all the traffic data of your website, slowing down your website with their trackers, and you have no control of that. For a webmaster, this is an uneasy situation.

The Simple Solution: No Javascript

The simple solution is to eliminate all the Javascript and add simple HTML buttons with sharing links provided by almost all social networks. This entire code will be purely HTML and CSS without Javascript.

I have created sharing buttons for some popular social networks and included the required CSS for the buttons. You can add your styles as well. In case you need an even better look, you can also add icons to your buttons.


First, let’s create CSS for these buttons.

.button {
  text-decoration: none;
  display: inline-block;
  text-align: center;
  padding: .25rem .5rem;
  font-size: 1rem;
  font-weight: 300;
  border-radius: .2rem;
  color: black;
  background-color: white;

.button-facebook {
  background-color: #4267b2;
  color: white;

.button-twitter {
  background-color: #1DA1F2;
  color: white;

.button-whatsapp {
  background-color: #25D366;
  color: white;


In the case of Facebook, you will also need a Facebook App ID which is very easy to get. Don’t worry, you do not have to create an app. Just go to Facebook for Developers dashboard, and fill the form with new app details. A Facebook app will be created and added to your Facebook developers account. Once you get the app id, use it in the following code to add simple Facebook sharing buttons.

<a href="" target="_blank" title="Share on Facebook" class="button button-facebook" rel="noopener noreferrer">Facebook</a>


<a href="" target="_blank" title="Share on Twitter" class="button button-twitter" rel="noopener noreferrer">Twitter</a>


<a href="//" target="_blank" title="Share on WhatsApp" class="button button-whatsapp" rel="noopener noreferrer">WhatsApp</a>

These are just three, but you can add any number of buttons of different social networks based on the sharing link provided in their documentation.

These links are simple HTML and CSS with NO Javascript. They do not add extra load on your page and give you the required functionality. You may miss the share count displayed on your sharing buttons, but it is not needed and the downsides of adding it to your website are simply not worth it.

So, just add these buttons to your website posts and pages to replace the heavy sharing widgets, and move towards a faster, cleaner code and a fast loading website.

Web Development

Add url rewriting router to PHP built-in server

While developing a project, PHP built-in server is much more flexible and easy to use compared to desktop setups like LAMP, XAMP, WAMP, etc.

However, without Apache, you also lose access to the magical and powerful .htaccess feature where you can create simple rewrite rules.

What if our application needs such rewrites like loading .html files for permalinks without extension?

Don’t worry. PHP provides an excellent and simple solution for this as well. You can create your router.php and call it while starting the server. Now, you are free to add any rewrite rule or any other condition to run your code.

To do this, create a file named router.php in your project root. You can choose any name for this file, but router.php provides the right context.

In this use case, I have a static website with all the static content like HTML, CSS, etc. But my permalinks are without HTML extension, though the file name is the same. I want to write a router that can rewrite my permalinks to .html version and at the same time, not mess us my style (.css) and script (.js) files.

Here is the code which I wrote for my particular use case. You can modify it to suit your requirements.

// router.php

// Get the url path and trim leading slash
$url_path = trim( $_SERVER[ 'REQUEST_URI' ], '/' );

// If url_path is empty, it is root, so call index.html
if ( ! $url_path ) {
    include( 'index.html' );

// If url_path has no dot, it is a post permalink, so add .html extension
if( ! preg_match( '/[.]/', $url_path ) ) {
    include( $url_path . '.html' );

// In case of css files, add the appropriate header
if( preg_match( '/[.css]/', $url_path ) ) {
    header("Content-type: text/css");
    include( $url_path );
    // You can do the same for other file types as well

Your router.php is ready. Now, open your terminal, go to the project root and start the PHP server with the following command.

pathtophp.exe -S localhost:8000 router.php

Finally, open your website by going to localhost:8000 on your browser. It works. Great.

Please note that this method is good for small applications so that you can quickly do a test run and check the code without deploying it on a proper server. In the case of bigger applications, this setup may become complicated as it is difficult to scale.


Enable browser caching in WordPress using htaccess

Browser caching is very important for any website as it helps in speeding up the website as well as reduces bandwidth costs.

To enable browser caching on Apache, you must have the required modules enabled.

If you are on a shared host like GoDaddy or HostGator, these modules are already enabled in most cases. So, you can skip the following steps and directly go to the htaccess code given at the end of this post.

In case, you are on a cloud server like DigitalOcean, you may need to enable these modules which can be done in following easy steps.

Open your terminal and run following two commands.

sudo a2enmod headers
sudo a2enmod expires

Now restart the Apache server by running following command.

systemctl restart apache2

It will ask for authentication. Enter your password and Apache will restart.

You have successfully enabled Headers and Expires modules on your Apache server.

Now, open the root folder of your website and create a .htaccess file with the following content.

# BEGIN cache-control
<IfModule mod_expires.c>;
    ExpiresActive on
    ExpiresDefault "access plus 2 days"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/x-ico "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 month"
    ExpiresByType text/html "access plus 1 seconds"
    ExpiresByType text/xml "access plus 1 seconds"
    ExpiresByType text/plain "access plus 1 seconds"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType application/xml "access plus 1 seconds"
    ExpiresByType application/rss+xml "access plus 1 seconds"
    ExpiresByType application/json "access plus 1 seconds"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/x-javascript "access plus 1 month"
    ExpiresByType application/pdf "access plus 1 month"
  <IfModule mod_headers.c>;
       Header unset ETag
       Header unset Pragma
       Header unset Last-Modified
       Header append Cache-Control "public, no-transform, must-revalidate"
       Header set Last-modified "Tue, 1 Oct 2014 10:10:10 GMT"
# END cache-control

And that’s it. You do not have to restart your server now as .htaccess file works in real-time. All the files served from your server will now be cached in the user’s browser as per the expires directive mentioned in the .htaccess file. You may also change these to any value of your liking.

CAT Preparation

Should you quit your job for CAT Preparation?

Common Admission Test (CAT) is the gateway to IIMs and other prestigious business schools in India. But at the same time, it is regarded as one of the toughest exams to crack due to very high competition.

A lot of aspirants prepare for CAT after their graduation while on a job. And if you are in a hectic job, you may find it very difficult to concentrate on your studies.

So what should one do in such a scenario? Is it a wise choice to quit the job and start CAT preparation with full dedication? Or, is it possible to prepare for CAT while working full time? Let’s find out.

As a business manager, in life, you will have to make difficult decisions. Consider this decision as one of them. And to take any important decision, you need to sit calmly and think about what options do you have and what would be the outcome of each option.

CAT is not a knowledge-intensive exam. It is a conceptual exam which needs a lot of practice. The syllabus of CAT is very limited. One can easily cover the basic concepts in a couple of months. The time taking part is to practice as many questions as you can. And practice needs discipline and sincerity.

It does not matter how many hours a day you study. What matters is that you do it every day, even though it is only for one hour each day. This kind of regularity is needed to master the concepts. Another aspect is mock tests, which you should take very sincerely.

If you are preparing for CAT or planning to start soon, you can read my detailed article here: How to start preparing for CAT

The complete list of books and material you will need for your CAT preparation can be found here: List of Important CAT Preparation Books

Now lets come to why people quit their jobs to prepare for CAT. Most of the time it is a bad manager, less salary or disillusionment with the current job. It makes sense to leave something for something much better. But you have to decide the right time to do it.

Having a job has multiple advantages for your CAT preparation as described below.

1) Without a job, you are in a do-or-die situation

If you have a job, no matter what happens, your career is not ruined. A jobless preparation becomes a do-or-die scenario because one has to have a career no matter how they perform in CAT. This puts undue pressure on the candidate and many times they are not even able to concentrate as much as they could if they prepared along with their jobs.

2) Job gives you a routine

This may seem trivial, but when you are working, you have a fixed routine everyday. You wake up on time, go to office, eat on time, sleep on time. Your efficiency is very high and you try to utilize every free minute you find during the day to prepare for CAT. When you leave your job, you have no compulsion to follow this routine anymore. And that’s where you lose focus. Without a routine, without discipline, you unknowingly waste time and your efficiency gets low. Combined with the first point above, it is a disastrous situation to be in.

3) Pre-MBA experience matters in campus placements

If you left your job for preparation and got into your dream B-School, your pre-MBA job experience will still play a role in your campus placements. It is usually easier to answer job based questions in interview compared to academics. Many companies count this experience to calculate offered CTC and designation. Even a few months of extra experience may get you a higher position at a better salary compared to your classmates.

4) A gap is a negative point in your CV

Quitting job to prepare for CAT puts a gap in your CV which is hard to defend in any job interview. No matter what you say, you are seen as a quitter who could not handle job pressure along with studies. This may not be true for you, but for an interviewer, this matters and it can ruin one’s chances to get the job.

5) A job is your plan B

Job acts as a plan B in case things do not turn out as you wish. A lot of aspirants argue that thinking about a plan B is doubting their capability even before they start. This thinking is wrong, as it does not consider the unpredictable scenarios. One may be perfectly capable of cracking the exam, but life is full of uncertainties and it does not harm to have a backup option.

6) Your savings will help you pay your bills

This may not look like a critical point, but it does have its own importance. If you are selected into multiple B-Schools, sometimes you need to pay booking amount for multiple colleges in case you are waiting for your dream college convert. Your savings from job will help you pay these. Also, with each passing year, MBA is getting more expensive. Even if you get into an IIM, you will have to pay more than 20 lakh rupees just in fees, accommodation, food etc. Add your personal expenses to this, and the amount will increase even more. Though you will easily get collateral free education loan as this is a risk free loan for banks, it will definitely ease you if you have some savings from your job which you can use either to pay first installment of fees or for your personal expenses.

All these factors are important and should be considered while making the decision.

When I was preparing for CAT, I was working too. I was tempted to leave my job based on reasons similar to most other CAT aspirants. It was a very hectic job coupled with many other factors. But I did not. And it was a good decision.

I always advise against leaving your job for CAT preparation. However, there may be exceptions and one should take this decision based on their own circumstances.

I hope my experience and views will help you make the right decision.


How to count words in Unicode string using PHP

How to count words in Unicode string using PHP?

How to count words in Unicode string using PHP? This sounds too easy. After all, PHP has so many string manipulation functions. To count words, we can simply use str_word_count and we are good to go. But there is a problem.

While this function works fine for English strings, developers find this function unpredictable as sometimes it also counts some symbols. But the real problem is that this function doesn’t work accurately for Unicode strings.

I faced this problem while working on one of my websites which is entirely in Hindi. When I searched, I was surprised to find that there is no straight forward solution or function to do this. There should be a standard function which should work for all languages, but the variation in structure of languages does not allow this.

A new function to count words in Unicode string using PHP

So, I wrote a small function which can be used anywhere to count the words in a Unicode string and works for a large number of popular languages. It first removes all the punctuation marks & digits to ensure that we do not count them as words. Then it replaces all white space blocks, including tab, new line etc., by a single space character.

Now all words of the string are separated by a single space separator. We can simply split/explode them into an array and count its elements to find the word count.

You can see the code below.

Just copy this code to your PHP project and start using this function to count words in any Unicode string.

And this is equally good for English strings as well. I found it more accurate than str_word_count.

Remember, it will work accurately for all those strings where spaces are used for word separation. But it may not work accurately for languages like Mandarin, where words are not separated by spaces.

Please do let me know how you like this article "How to count words in Unicode string using PHP" through comments section below.


I missed you too

It was the best she ever looked. She was determined to fix everything today. Her flowing hair shining like gold fluttered through the breeze. Once again she looked at her cellphone mirror. “Perfect. He would love to see me.” She said to herself.

It was a bright day, full of sunshine. As she walked by the corner of the main market road, her eyes followed her image reflecting in the huge front glasses of the shops. “He still loves me like old days. We will be together now.” She couldn’t resist talking to herself.

After a long walk along the market main road, the residential area was in sight. She took a deep breath to prepare herself once again. She felt even more confident causing her to speed up. The white castle was now just a few steps away.

It was a small bungalow painted pure white. When sun gazed at it in broad daylight, it shined like a dazzling white monument surrounded by lifeless stones. She crossed the gate and walked inside into the main hall.

He was sitting in a corner on a wooden chair with a small table in front of him. There was a glass chess on the top of the table and it seemed like the game was at full swing. He was in deep thought thinking about the next move and didn’t notice her arrival.

She quietly walked towards him and sat on the empty chair opposite to him. He was still immersed in the game looking into the emptiness. Something clicked and he rose his head with a huge smile. “Check & mate.” he cheerfully declared. His eyes were shining like he has won the world.

She looked at him & smiled. His happiness made her happy. His joy made her cheerful. For a while, she forgot why she was here and felt the moment. He won. She felt as if she had won too.

She waited for a few seconds as he settled down. As he rose his head, he finally noticed her. Along with the smile, a tear came rolling down his cheek. He was speechless. She was as beautiful as she had always been.

He rose up from his chair and moved towards her. She rose up too. He hugged her so tightly as if this moment was going to last forever. It was what they both always wanted, to be together.

A loud voice startled them both. “How dare you?” A huge man appeared from the inner house with an angry face. “Get out now, or I will call the police.”

He froze and felt helpless loosening his arms around her. But she was determined today. While she held his hand, her other hand slowly slipped into her purse which was hanging on her shoulder and she grabbed something. A loud sound, and the man was lying on the floor, surrounded by his own blood. “It ends today” She murmered.

She turned back to see him horrified. “It’s over. No one is going to hurt us anymore. We will go far away from all this. I missed you so much.” As he looked in shock, she slipped her gun back into her handbag and started walking towards the door still holding his hand.



“I missed you too, Mom” he finally said and followed her out while looking back at his father’s motionless body. The headline of a local newspaper kept on the center table loudly read “Mentally unstable wife accuses husband of child abuse, escapes from asylum.”

CAT Preparation

List of Important CAT Preparation Books

A lot of candidates ask me about the important CAT (Common Admission Test) Preparation books to be referred while preparing for CAT.

In this post, I will give you complete list of important books for CAT Preparation. Also, I will share some good resources/material which will help you a lot in your CAT preparation.

I have included links to most of the books & resources. This list is the latest list of books updated for CAT 2019 preparation.

If you are preparing for CAT or planning to start soon, you can read my detailed article here: How to prepare for CAT

List of Important CAT Preparation Books

The All-in-one

If you are not willing to go through multiple reviews for CAT preparation books, you may go for this bundled package of 4 books for complete CAT preparation by Arun Sharma And Meenakshi Upadhyay.

Continue reading below for topic-wise list of books from multiple authors as well as some additional books.

Quantitative Ability

There are two good books for Quantitative Ability. Practicing only one of these is enough for your preparation.

How to Prepare for Quantitative Aptitude for the CAT by Arun Sharma

This is the most popular book for quant preparation. It is a very good book with questions segregated into different difficulty levels.

Quantitative Aptitude Quantum CAT For Admission into IIMs by Sarvesh K. Verma

This is another good book. It was suggested to me by a friend and I referred to this book for my Quant preparation.

Verbal Ability

This is the most important section of CAT which becomes the reason for unexpected CAT scores. Following books should be referred for this section.

Word Power Made Easy by Norman Lewis

This is the most important book of your entire CAT preparation. Read it from end-to-end as per the instructions in the book and your vocab would never be the same.

How to Prepare for Verbal Ability and Reading Comprehension for CAT by Arun Sharma & Meenakshi Upadhyay

This is a good book for Verbal Ability and can be used as the base reference.

Wiley’s ExamXpert Verbal Ability and Reading Comprehension for CAT 2019

This is another popular book for verbal and reading comprehension preparation. You should go only for one of these two books.

Apart from these, for Verbal Ability and Reading Comprehension section, you must have excellent English language skills which can be developed through regular reading. I have written a detailed article about this which you can read here: How to Develop the Habit of Reading

Data Interpretation & Logical Reasoning

DI & LR are very scoring sections of CAT and should be handled very efficiently. I have listed three books here- two individual books for DI & LR each, and one book for both DI & LR. Do not get all three. Either get first two books, or the third one.

How to Prepare for Data Interpretation for the CAT by Arun Sharma

This book by Arun Sharma is a popular choice for DI.

How to Prepare for Logical Reasoning for the CAT by Arun Sharma

This is a book on Logical Reasoning by Arun Sharma.

Logical Reasoning and Data Interpretation for the CAT by Nishit K. Sinha

This is a good book which covers both the Data Interpretation & Logical Reasoning. You can practice DI & LR questions from this book.

Previous Year’s Papers

Once you get through the basics, start practicing previous year’s papers. It will give you a good idea about the exam. You can choose any book as the questions are going to be the same. The following is the latest available book containing last 24 years CAT solved papers.

24 years CAT Topic-wise Solved Papers (2017-1994) with 6 Online Practice Sets 11th edition

Study Material

If you complete these books, you may also refer to the study material of any one good coaching institute. No need to collect material from multiple institutes. You can even take someone’s old material which may be equally useful.

For quant, study material may not be of much use to you as you will get a lot of questions in various books. But the study material may prove beneficial for Verbal Ability, Data Interpretation & Logical Reasoning. Try to practice all the questions from these topics.

I hope this information would prove useful to you and you will crack the CAT and secure a seat in an IIM.

All The Best.


My Idea of a Peaceful Dream Vacation

A group of ducks enjoying the peaceful life of Mysore (Infosys Mysore Campus)
A group of ducks enjoying the peaceful life of Mysore (Infosys Mysore Campus)

We come across so many beautiful people, places and moments in our life. At times, we feel to revisit those moments, to relive the amazing past. Such nostalgia occurs to me every now and then. The memorable moments of my life I spent in Mysore.

Yes, it is my dream vacation destination where I want to spend some quality time again. Away from the chaos of daily life, a place with still lower level of pollution, a place housing one of the best corporate campuses on earth- Infosys Mysore.

It should be at least 1 month long vacation. I would leave from Delhi Airport to land in Bengaluru and from there I would take a cab to Mysore, the city of peaceful life. I can imagine the cool breeze entering my car and touching my face. The weather is amazing throughout the year.

I want to book a guest house, not a typical hotel, but an independent villa-type house, slightly outside the main city, entirely for my use during the vacation duration. It would be a place where I would feel like home. It would be a place where I would not have room service to disturb me or next room neighbors to create any noise.

I will spend the first week roaming around the city everyday and visiting the beautiful places like Mysore palace, Chamundi hills, Vrindavan Garden etc. The city is known for yoga and I want to practice it too while connecting with the people who passionately practice the art of yoga.

A very nice place near to Mysore is Ooty. A beautiful hill station known for its huge expanse of tea farms. It is such a beautiful place that one can forget everything while visiting this heaven. The views from some of its points is so breathtaking that one can sit there and enjoy for hours just by looking at the natural landscape and enjoying the cool breeze. I will visit there for at least 3-4 days hiring a cab service for daily commute.

Two things which are very famous in Ooty are homemade chocolates and tea factory. The tea factory manufactures so many varieties of tea including chocolate flavored tea. One can buy a ticket to even visit the factory and witness the whole production process. At various points, they offer you sample tea of different flavors which is a delight to taste. I will not be able to leave that place without buying at least a few kilos of tea powder.

Another place in Mysore I want to visit is Infosys Mysore campus. It is a beauty in itself. I spent 6 months in training while staying in the campus and next 6 months working while living in Mysore city and the memories of this whole year are still so fresh. One can take days to completely roam the campus on foot and golf carts and parked cycles are a must to expedite the exploration. A day or two there will freshen me up a lot.

For the remaining 2 weeks, I would rather chill out and enjoy the weather, place, people and the life in Mysore. I am sure it would completely recharge me to get back to the same energy level I had when I first visited this place and while going back to Delhi and arriving at the Delhi Airport, the smile on face would be the shiniest of all.

To book your flight ticket, cabs, hotels etc. easily, you may log on to and get great deals on domestic air tickets on Domestic Airlines.

CAT Preparation

“New IIM” vs “Old” Private B-School

The new IIM dilemmaEvery year, a lot of students get confused between getting into a “new IIM” or established “non-IIM private” B-schools. I hope this article will help them in making a choice.

In last 8 years, we witnessed 13 new IIMs which brought the total number of IIMs to 19 in India. CAT aspirants, who are unable to secure admission in older IIMs and get selected in new IIMs, find themselves in a huge dilemma whether to join these new IIMs or some already established premier non-IIM B-School.

With a lot of opinions of so many so-called “experts”, it is obvious for a prospective B-school student to get confused. So, lets try to find a solution to this problem by analyzing some facts.

Let us first look at what is the current general perception. I heard many people say that new IIMs are not good. They swear by other established non-IIM B-Schools. The sole reason for them is good placements in those colleges compared to new IIMs. Other than that, old established colleges have good faculty, thus good education, good infrastructure and finally good alumni base (which is again good for placements). I do not think there is any other reason due to which these people prefer other B-Schools over new IIMs.

Now lets see what it actually means to be a “good MBA”. As per my understanding, apart from classroom teaching, MBA is mainly about “peer learning” while performing different tasks together in teams. Unlike technological courses, it does not require any sophisticated infrastructure/laboratories other than decent classrooms, auditorium, seminar hall, computer lab, library and faculty/staff cabins/offices. Other than that, any good college will provide some sports facilities and a decent residential facility (hostels).

As per my knowledge, all new IIMs, though operating in makeshift campuses, provide decent level of all these facilities through various means. So, good infrastructure may not be a differentiating factor.

Then comes the learning part. First we consider peer learning which means we need to have good students. As we know, the criteria for getting into IIMs is CAT which is considered one of the most difficult exams of the world due to its very low conversion ratio. For less than 4000 seats in IIMs, 2,00,000+ students are competing every year. This means that the conversion rate is less than 2% which is very low compared to top B-schools of the world.

Even for new IIMs the general cutoff has been near 97 percentile which is higher than or equal to cutoffs for most of the non-IIM B-schools. It means no general student of new IIMs has got percentile less than nearly 97. If good CAT percentile is indicative of hard working, sincere, intelligent and talented students, most of the students admitted to new IIMs are good and thus facilitate good peer learning.

Same is the case with faculty. In most premier colleges, there is a tradition of employing visiting faculty who are experts in their respective fields, along with permanent faculty. As a part of a new IIM with 15+ permanent faculty and 150 students in a batch, I have seen visiting faculty from old IIMs, other top B-schools and industry veterans for various courses. I do not think that I missed any superior kind of learning which I could have got in any non-IIM B-school.

Regarding the course structure, the pattern in new IIMs is almost similar to the older IIMs with similar subjects, electives and exam criteria.

The spirits of students are high in new IIMs as well. They organize events/fests, take part in (and win) various national/international competitions, celebrate majority of festivals, write research papers, attend conferences etc. I did not find anything significantly better in the description of such things happening in premiere non-IIM B-schools from people studying there.

Till now, we saw that when compared to premiere non-IIM B-schools, new IIMs does not have any significant difference or disadvantage in terms of infrastructure,learning, environment, and student spirit. Then where is the actual difference.

This brings us to a very interesting and highly controversial topic of placements. I do agree that old IIMs and a couple of non-IIM B-schools provide excellent placements. Apart from these, I find good placements in some other colleges, but not excellent.

And this is the case even with their huge alumni base. A new IIM without any alumni base getting placements comparable to long established non-IIM B-schools is a huge indication of the excellent quality of an IIM. It shows that the quality of students in IIM makes them not overly dependent on alumni for placements and industry is ready to offer them good profiles.

Moreover, the source of information of placements of any college is the placement report prepared and distributed by that college. There has been a history of highly inflated and misrepresented placement figures by many colleges. Can we actually believe the placement report of any college? I think, it would be better to consider more than just numbers. Though, in case of an IIM, you can try filing RTI to get true information.

May be the new IIMs are new, may be their inception (in 2010) coincided with the world-wide recession which caused them to begin with somewhat less but still decent placements. But is this slight “apparent” difference, the reason to miss the opportunity to study in an IIM?

Also, most of these non-IIM B-schools are expensive than new IIMs in terms of fees. Is it really worth it?

I have shared my viewpoint. You have to take your own decision while considering realistic facts and avoid getting influenced by irrelevant hype and rumors.

After all, an IIM is an IIM and its equally difficult to get into a new IIM.