Blogger Tricks

24 Jun 2012

How To Increase WordPress Loading Speed With Ajax Pagination

How To Increase Wordpress Loading Speed With Ajax Pagination loading speed of wordpressWordPress is a open source CMS (Content Managment System) lakhs of people use them dialy. So we have to increase the wordpress loading speed in order to open the website within less seconds which makes visitors happy and hence visitors won’t be get irritated.We had already covered a successful post on WordPress loading speed and optimization and tested. Here is the link of the previous post

In the previous post we have covered
  • Setting up CDN (content Delivery Network) with the wordpress blog.
  • Tweaked the .httaccess file like removing hotlinking( protect your images from bandwidth theft)
  • optimized images with the wp minify and wp smush it.
  • Using cache plugin using the Wp-total cache
  • Enabling Gzip in the.httaccess file.
So Now we are moving ahead with adding the ajax pagination effect in the wordpress blog .
Tutorial
  1. Log on to your wordpress dashboard .
  2. Go to Editor in your wordpress dashboard
  3. Now you can see source files of your wordpress blog.
  4. Find the header file (header.php) and click on it.
  5. Now you can see the header.php code , now here you have to add the following code before wp_head() function. You can find the wp_head() function by typing “CTRL +F” then type “wp_head()” and paste the following code before the header function.
    <?php wp_enqueue_script('jquery'); ?>
    <script>
    jQuery(document).ready(function(){
    // ajax pagination
    jQuery('#wp_pagination a').live('click'function(){// if not using wp_pagination, change this to correct ID
    var link = jQuery(this).attr('href');
    // #main is the ID of the outer div wrapping your posts
    jQuery('#main-container').html('<div><h2>Loading...</h2></div>');
    // #entries is the ID of the inner div wrapping your posts
    jQuery('#main-container').load(link+' #entries')
    });
    }); // end ready function
    </script>
  • So after adding above code in your header.php and click save button.
  • Finally you have optimized the website faster with Ajax pagination which makes your site even faster .