Friday 16 January 2015

Speed Up Your WordPress Website Performance With Varnish Cache

Lets face it, WordPress standard installation is slow. And installing a number of plugins, themes and images makes it a lot more slower. You can minify your CSS and JS with help of “Better WordPress Minify” plugin, or you can use EWWW Image Optimizer plugin to reduce your images file size. However, there are lot of other factors that affects your WordPress site performance.

Possibly by now, you'll be thinking to Hire WordPress Expert to get the job done. But, there's another viable solution. Wondering, what's the solution? Varnish Cache is a web-application accelerator which is designed for dynamic websites with heavy content.

Varnish Cache – A Foreword

This caching system stores copies of pages for readers who aren't logged in into WordPress admin. Whenever users requests for something it reaches to Varnish instead of the server. And then, Varnish looks for what user has requested and then forward the request to the server. The server sends the response to Varnish, which in turn sends that response to user's original request. But if Varnish would only perform such function, it wouldn't be much of help to us.

However, Varnish also help improve performance by storing the responses it has received from the server in the virtual memory. And so, Varnish is able to quickly send the next response to the user instantly from its cache, and thereby the load on server to process users requests is reduced significantly. This eventually help improves the response time and your process requests can be carried on great speeds.

How to Install Varnish Cache?


We’ll be setting up Varnish to listen to all web requests on port 80, while Apache will be supporting Varnish on port 8080. So, when Varnish will ask for a page that needs to be built manually, the request will get passed on to the Apache port 8080. Let's look at Varnish installation on our instance:


Edit Apache’s ports.conf file to listen on port 8080:



sudo nano /etc/apache2/ports.conf

You'll get the following outcome:

NameVirtualHost *:8080

Listen 8080



Next, you need to edit your “Apache” website config file in order to respond to port 8080:

sudo nano /etc/apache2/sites-available/wordpress

Now, change the virtual host from *:80 to *:8080

<virtualhost *:8080>


You'll require to change your Apache default website to listen for web request on port 8080 or need to disable it:


sudo a2dissite 000-default


In case, you've decided to review your original Varnish configuration files later, you'll have to move those files to your home directory in the form of backups.

sudo mv /etc/default/varnish ~/default-varnish-old

sudo mv /etc/varnish/default.vcl ~/varnish-default-vcl.old



Replace your default Varnish configuration file with the one given below (copy and paste).

sudo nano /etc/default/varnish



Let's look at the configuration file that needs to be replaced:

/etc/init.d/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK

# to be set from this shell script fragment.

#

# Should we start varnishd at boot? Set to "no" to disable.

START=yes

# Maximum number of open files (for ulimit -n)

NFILES=131072

# Maximum locked memory size (for ulimit -l)

# Used for locking the shared memory log in memory. If you increase log size,

# you need to increase this number as well

MEMLOCK=82000

# Default varnish instance name is the local nodename. Can be overridden with

# the -n switch, to have more instances on a single server.

# INSTANCE=$(uname -n)



How to Configure Varnish?

Once Varnish is installed, edit your port and change it to 80. Just remember not to change your Apache port yet, and keep it running till you're sure that everything complies properly. Moreover, if you're not sure about your configuration files, configure Varnish for port 81, and the perform a side-by-side test without losing your users:

nano /etc/default/varnish

DAEMON_OPTS="-a :80 \

             -T localhost:6082 \

             -f /etc/varnish/default.vcl \

             -S /etc/varnish/secret \

             -s malloc,256m"



Next, make you'll need to make copy of the original VCL file:


mv /etc/varnish/default.vcl /etc/varnish/default-old.vcl


Configuring Apache


After configuring your Varnish cache, edit your Apache (or HTTP Server) so as to use some other port. (8080) Make sure to verify whether virtual host also configs or not.

nano /etc/apache2/ports.conf

NameVirtualHost *:8080

Listen 8080


Now restart the HTTP Server and Varnish. Varnish will listen to HTTP (web) traffic on port 80, and Apache in 8080.  But, how does Varnish will come to know where it needs to look for the HTTP Server? For this purpose, look at the top of default.vcl file.


/etc/init.d/apache2 restart

/etc/init.d/varnish restart

Getting Rid of Content from WordPress


In case you need to purge your WordPress website content manually or automatically when the posts are saved, install the Varnish HTTP Purge extension to your site. For doing so, add the following line of code to your
wp-config.php file:

define('VHP_VARNISH_IP','126.0.0.1');


Wrapping Up!


Adding plugins, images and other elements to your WordPress site makes it sluggish. However, you can make your WordPress site performance faster with help of Varnish Cache. This post will help you gain insight on Varnish cache, it's installation and configuration. 

Tuesday 6 January 2015

A Comprehensive Guideline on managing coupons with WooCommerce

As an owner of a WooCommerce enabled e-store you'd have definitely enjoyed multiple features and functions that come with the WooCommerce tool-kit. Coupons are one of the best-known tools for making your customers come back to you on a repetitive basis. If you are planning to offer discounts and rewards to your customers then learning about the WooCommerce Coupon Management utility is something you'll regret missing.


If you've ever chosen to hire WordPress developer, you might be well familiar with the pros associated with building a coupon website using WordPress. Through this blog, I intend to share with you all the key steps that mark efficient handling of various discount coupons which are being made available to the product purchasers.

So, let's come to the steps now:

Step 1- Activate the use of coupons on your WooCommerce e-store

As the very first step, you need to inform WooCommerce that you'll be using coupons on your e-store. For this, you simply need to go to your WooCommerce admin dashboard where you need to click on the 'Settings' option available within the left hand sidebar. Now, click on the 'Checkout' tab available on this page and against the label 'Checkout' simply select the check-box for “Enable the use of coupons'. The screen-shot for this step is displayed below:


 
Step 2- Add new coupons

In order to add a new coupon, simply scroll down within the left-hand sidebar and click on 'WooCommerce'. After this, click on 'Coupons' . A page similar to the one shown below will be displayed:


On the Dashboard, scroll down the left-hand sidebar and click on “WooCommerce”, before clicking on “Coupons” from the dropdown that appears. The coupons page consists of a box that shows all of the coupons you have created so far. To create a new coupon, click “Add Coupon” at the top of the page. Thanks to the quick availability of WordPress plugin development professionals, we can easily get access to a wide range of plugins custom-made for performing tweaks to a WP-powered site/blog.
Coming back to the tutorial, on the above page, click on 'Add Coupon' button. A page similar to the one shown below will be displayed:


On this screen, you'll be required to enter values for the following fields:
  • Coupon Code- Use this textbox for specifying the code that the users would need to enter in order to apply for the respective coupon.
  • Description- Use this text-area for entering a brief description for the coupon. This information would be displayed along with the coupon on the front-end.
Once you're done with inputting values for the above fields, proceed ahead with specifying coupon data which is being segregated into the following sections:
  • General
The screen for this section is similar to the one shown below:
 
So, the fields covered on this form include:
  • Discount Type- Use this dropdown for selecting the discount type in relation to the respective coupon. You may choose from the following options available within this drop-down list:
1. Cart discount- Select this option if you want to offer a fixed total discount for the entire shopping cart.
2. Cart % discount- Select this option if you want to offer a percentage discount for the entire shopping cart.
3. Product discount- Select this option if you want to offer a fixed total discount for only a selected group of products.
4. Product % discount- Select this option if you want to offer a specific percentage discount for a chosen group of products.
  • Coupon amount- Use this to enter a fixed value or percentage discount on the basis of the discount type chosen above. Here, please note that a value entered without the currency unit or percentage sign will be automatically added, for example: a value entered as 20 will be treated as 10% or $10.
  • Allow free shipping- Select this checkbox if you want to enable free shipping(i.e. Zero shipping cost) for the product(for which the respective coupon has been used)
  • Apply before tax- Select this checkbox if you want the discount coupon to be applicable on the product well before the tax calculation for the same.
  • Coupon expiry date- Use this date picker for selecting the data which when passed will make the coupon invalid for use.
  • Usage Restriction
The screen for this section is similar to the one shown below:


The fields covered within this section are explained below:
  • Minimum spend- Use this textbox for setting a minimum sub-total that the user needs to have in order to avail the respective coupon. The customer's cart sub-total+tax will be compared to the value entered here.
  • Individual Use only- Select this checkbox if you don't want the coupon to be used in conjunction with other coupons.
  • Exclude sale items- Select this checkbox if you don't want the coupon to be applicable for products put on sale.
  • Products- Use this textbox for selecting products that must be added to the user's cart in order to enable him/her to apply for the respective coupon.
  • Exclude products- Use this textbox for selecting products that must not be added to the user's cart in order to enable him/her to apply for the respective coupon.
  • Product categories- Use this textbox for defining a list of product categories that the user's cart must contain in order to be eligible for availing the coupon.
  • Exclude categories- Use this textbox for defining a list of product categories that the user's cart must not contain in order to be eligible for availing the coupon.
  • Email restrictions- Use this textbox for specifying all the email addresses which are allowed to use the respective coupon. Values defined here are compared to the customer's billing email address.
  • Usage Limits
Screen-shot for this coupon data section is displayed below:

Fields covered here include:
  • Usage limit per coupon- Use this dropdown for choosing a maximum usage limit for the coupon before it expires.
  • Usage limit per user- Use this dropdown for choosing the number of times for which the coupon can be used by a user before it becomes invalid for him/her.
So with that you're done with the task of adding and managing coupons for your e-store.
Final Thoughts
If used appropriately, coupons can actually help you in boosting the visitors' count and conversion rate for your e-store. Hope the above mentioned steps would enable you to make the most of the 'Coupons' feature available with your WooCommerce e-store.



Thursday 1 January 2015

Allowing Your Visitors to Use Custom Post filters in Your Genesis Theme

Recently, I worked on an project and caught with an idea that I should share the case with. One of my clients wanted to use the custom post filter in his genesis theme to get rid of the “post” navigation since he was running a review website. And its justifiably so since it seems misleading to the audience because they aren't reading the actual posts but only reviews.


One of the best things about genesis framework is that its flexible enough to serve the diverse needs of its users at the time of custom WordPress development. Genesis comes with rich “filter” functions under the theme settings area, which lets you place the desirable text on the basis of the taxonomy (terms/categories/tags) at the end of the index page.

Altering this text within the genesis framework isn't an uphill battle. All you need is simply go to your latest Genesis (v1.6) wherein it's quite easy to filter older/newer and next/previous text in the post navigation.


Getting The Grips of Older / Newer Post Navigation Filter

One can easily perform modifications within the Genesis with the help pf the functions that reside under the Genesis Theme Settings. Exploring this particular area you'll assess Content Archives, where there is an option called Post Navigation Technique”, already set as Older/Newer. Here, the default output is “Older Posts and “Newer Posts”, and in order to filter this, the below mentioned code should be added to your child theme's functions.php file. Here I have changed the example as to read Older and Newer Reviews.

add_filter( 'genesis_older_link_text', 'gt_review_older_link_text' );
function gt_review_older_link_text() {
$olderlink = '&laquo; Older Reviews';
return $olderlink;
}
add_filter( 'genesis_newer_link_text', 'gt_review_newer_link_text' );
function gt_review_newer_link_text() {
$newerlink = 'Newer Reviews &raquo;';
return $newerlink;
}

Previous / Next Post Navigation Filter

This filter is just like the one we have just mentioned above except that it runs when the “Select Post Navigation Technique” which we find under the Content Archive is set to Previous/Next instead of Older/Newer. Here also we are getting a default output, which is “Previous Posts” and “Next Posts”. To filter this, we have to add the following code within the functions.php file which you can get inside the child theme. In this example too we have edited it to Read Previous and Next Reviews.

add_filter( 'genesis_prev_link_text', 'gt_review_prev_link_text' );
function gt_review_prev_link_text() {
$prevlink = '&laquo; Previous Reviews';
return $prevlink;
}
add_filter( 'genesis_next_link_text', 'gt_review_next_link_text' );
function gt_review_next_link_text() {
$nextlink = 'Next Reviews &raquo;';
return $nextlink;
}

And that's all you have to do. See pretty easy right?

Genesis is a great framework with some truly astonishing settings that help you create a website that helps you serve your client's needs efficiently. Its customization abilities are unique and they allow you give your website and its readers what is actually useful to them.

However, if you want to learn some more methods and ways to filter custom posts than you can rely upon some handy plugins like Beautiful Taxonomy Filters . The plugin can be described absolutely dynamic when it comes to add filtering to your custom post types archives based on taxonomies. The plugin is extremely useful to filter CPTs in the manner most effective.

To know more about this plugin, Beautiful Taxonomy Filters allows you alter rules to create pretty filter URLs by eliminating the need to use JavaScript. It helps you spruce up your custom posts type archives by allowing visitors filter posts on the basis of their terms or categories. The plugin does everything for you in the most seamless way. The plugin works automatically, without having any need to use JavaScript, and the best part is it is based on WordPress Plugin Boilerplate which allows you organize the codebase using the object-oriented approach.

The plugin is capable enough to handle and include as many as filters. However, if you have post type with varied taxonomies, you can better keep out those who aren't useful for filtering.

Some of the other highlighted features include:

  • Active filtering on any registered public custom post type.
  • Keep those taxonomies out you don't want your visitors to filter on
  • Comes complete with functional filter component which you can put in your theme.
  • Visitors can be presented with the information regarding their current active filtering.
  • Integrated with custom GET parameters.
  • Additional filters, settings, and actions to fine tune the filter module behavior.

The plugin provides a convenient and fast way of adding multiple taxonomies to filter custom post types archives. One can also easily extend its capabilities and actions to make it more compelling and versatile. I personally have tested this plugin and found it to be extremely great in the way it helped me to achieve my goals. So, you can also use it whenever the needs arise. It will not disappoint you for sure. Even if you are not confident about your skills you can better hire a WordPress developer, who will deploy his skills and knowledge to give you exactly what you have in your mind in an efficient manner.