Tuesday, February 24, 2015

How to Use WordPress Jetpack Offline

Jetpack comes with plenty of modules to help you use contact forms, utilize infinite scrolling, shortcodes, and a whole lot more. These features can help turn your self-hosted WordPress website to be as powerful as websites are hosted on WordPress.com. However, there is a disadvantage that comes with the tool, it only works with you online, and when logged onto WordPress.com.


Basically, you can only use all these features on a live site. Upon activating the plugin you will immediately see this nagging banner appear at the top of the Dashboard.



Want to know how to get it to work offline so you can develop your theme in peace? Here’s how. Note: before installing Jetpack, ensure that your website is running WordPress is 3.8 or later.



Jetpack 2.2.1


Since the 2.2.1 version, Jetpack has introduced the Development Mode, which tells Jetpack that we are in development and it should activate the features. Add the following line in the wp-config.php after the WP_DEBUG line.



define("JETPACK_DEV_DEBUG", true);

If you don’t want to edit wp-config.php or if you do not have access to the file, you can install this plugin, Run Jetpack Locally, instead. It’s a tiny plugin containing the following line (basically an alias to JETPACK_DEV_DEBUG).



add_filter( "jetpack_development_mode", "__return_true" );

Now, head over to the Jetpack > Settings page. You will find that the banner is now gone and Jetpack is officially in Local Development Mode.



Jetpack is now available offline. A number of plugins should now be activated, including Infinite Scroll. These enabled plugins can work independently of a connection to WordPress.com API. Other features such as Photon and Stats, however will require the WordPress.com API.



An Alternative Route


If you aren’t satisfied with the fact that only some of the features are enabled, there is a way to get them all up and running while keeping Jetpack running offline.


First of all, let’s make our local website accessible online in order to be able to connect to WordPress.com; to do so we will be using localtunnel.



Once you have it installed, run the following command in Terminal to make your local host directory online.If you are using MAMP, the directory is most likely located at “/Applications/MAMP/htdocs”.



lt --80

Localtunnel should now give you the address where you can access the localhost in the browser, like so:



Before you access the website through the given address, you will need to go to phpMyAdmin or other similar apps that allows you to look into the website’s database. Open the website database and go to the wp_options table. Then change the website URL in the siteurl and home to point to localtunnel, like so.



Access and login to the website through the new address. Since your website is now online, WordPress.com should be able to reach and connect to your website.



And there we go, we have the website connected to WordPress.com, and you can use all the modules in Jetpack.



Reminder: Don’t forget to switch the website address in the wp_options table back afterwards.


What’s Next?


You might be wondering that in the case where we are developing multiple website offline, should we connect each of the websites in localhost to WordPress.com this way? Well, you don’t have to.


Once you have 1 website in your localhost connected, you can simply copy the jetpack_option value into the other websites. To do so, go to phpMyAdmin. In the wp_options table of the website that you have connected to WordPress.com, copy all the values of the jetpack_option, as follows:



Paste the value to the other websites, where Jetpack has been activated. Now, as you can see below, we are able to activate and use all the modules offline in the other websites we are developing locally.



Keep in mind, that this trick is meant to let us use Jetpack while we are testing it against our theme or plugins during the development process. If you have your website online, you should connect it properly.



How to Use WordPress Jetpack Offline

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.