If there is an update for installed theme in WordPress websites, you can see them in the Theme menu. There is two options to update the theme. You can update them from WordPress website or from your own website. WordPress theme update is not only from wordpress.org. You can create your own updating system for your theme from your own website.
To do that, open functions.php file and add code below in the file and save it.
add_filter('site_transient_update_themes', 'hs_theme_check_for_update');
function hs_theme_check_for_update($transient)
{
// Check Theme is active or not.
if (empty($transient->checked)) {
return $transient;
}
$remote = wp_remote_get('https://honarsystems.com/themes/your-theme.json', array(
'timeout' => 10,
'headers' => array(
'Accept' => 'application/json'
))
);
if (!is_wp_error($remote) && isset($remote['response']['code']) && $remote['response']['code'] == 200 && !empty($remote['body'])) {
$data = json_decode($remote['body']);
if (version_compare($transient->checked['your-theme'], $data->new_version, '<')) {
$transient->response['your-theme'] = (array)$data;
}
}
return $transient;
}
Change “your-theme” to your own theme slug.
As you see, there is a link to download a JSON file. In this file you tell the WordPress updater that where is your theme and version of the theme and other extra fields.
Create a JSON file and name it like in the url. Add code below in JSON file and save it.
{
"name":"your-theme",
"theme_slug":"your-theme",
"new_version": "1.0.2",
"url": "https://honarsystems.com/themes/your-theme/changelog/",
"package": "https://honarsystems.com/themes/your-theme.zip"
}
Package field, pointed to your new theme zip file that the WordPress updater will update the theme from it.
Upload the JSON file in the directory that we added in functions.php file. In my code it is “https://honarsystems.com/themes/“. If you go to the link, you will see the content of the JSON file.
