WordPress how to work safely on a live site

103 Likes Comment

Sometimes there are situations when you need to work on a live site due to the fact that there is no local version or it is generally impossible to implement because of the large amount of data on the site.

For example, you have a theme called live. Then you can create a copy of this theme and name it for example live.dev.

Go to directory wp-content/plugins and create a new file there wp-dev-theme.php. Place the following contents. Don’t forget to activate the new plugin via Dashboard of WordPress.

<?php

/*
Plugin Name:    Develop Theme
Version:        1.0.0
Author:         Oleksandr Sovenko
Author URI:     https://oleksandrsovenko.com
License:        GPLv2 or later
*/

// xxx.xxx.xxx.xxx - your IP-address
if ($_SERVER['REMOTE_ADDR'] == 'xxx.xxx.xxx.xxx') {

// or you can use cookie
// if ($_COOKIE['DEVELOPER'] == 'true') { 

    add_filter('template', 'dev_theme');
    add_filter('option_template', 'dev_theme');
    add_filter('option_stylesheet', 'dev_theme');
    function dev_theme($theme) {
    	return 'live.dev';
    }
}

?>

This plugin will switch you to theme live.dev in real time. This way you can work on a live server safely. You will not disturb users.

After fully debugging a new theme, you can simply copy the files into a live theme.

Enjoy!

You might like

About the Author: Oleksandr Sovenko

Back-End Web Developer. Currently I spend my days working as a remote web developer of EstPress

Leave a Reply

Your email address will not be published. Required fields are marked *