• Hi – I’ve been developing WordPress websites for many years, mostly custom themes for clients to log into and make it easy to maintain their content. I have a client now who uses the same theme across multiple franchise websites that they maintain. Issue is changes get applied to the theme and then those changes have to be implemented into each of the franchise websites and make the same changes (CSS, JavaScript, PHP files and the biggest one is new “Advanced Custom Fields” fields).

    So my question is, can anyone point me to some good documentation on how to make the theme updatable meaning I’ll have the .zip on my server and the sites with theme installed will ping that address to check for updates and if needed, update. Trying to search around and all I run into is “how to update your theme on WordPress”.

    Thanks a bunch!

Viewing 1 replies (of 1 total)
  • I take it you have a good understanding of coding since you develop themes, so hopefully the following can get you on the right track:

    1. Create a function that will check for updates: You can use the wp_remote_get() function to send a request to the URL where the version information is stored, and then parse the response to get the version number. Here is an example:
    function check_theme_update() {
        $url = 'https://example.com/theme-version-checker.php';
        $response = wp_remote_get( $url );
        if( is_array( $response ) ) {
            $version = $response['body'];
            // Compare the version number with the current version of your theme
            if( version_compare( $version, '1.0.0', '>' ) ) {
                // Update is available
                // Add a notice to the WordPress admin dashboard
                add_action( 'admin_notices', 'show_theme_update_notice' );
            }
        }
    }
    

    2. Add an action hook to check for updates: You can use the after_setup_theme action hook to call the check_theme_update() function when the theme is initialized. Here is an example:

    add_action( 'after_setup_theme', 'check_theme_update' );
    

    3. Add a notice to the WordPress admin dashboard: You can use the admin_notices action hook to add a notice to the WordPress admin dashboard when an update is available. Here is an example:

    function show_theme_update_notice() {
        ?>
        <div class="notice notice-warning">
            <p><?php _e( 'A new version of the theme is available. Please update as soon as possible.', 'text-domain' ); ?></p>
        </div>
        <?php
    }
    

    Note that you will need to replace https://example.com/theme-version-checker.php with the URL where the version information is stored for your theme, and 1.0.0 with the current version of your theme. Additionally, you can customize the notice message by changing the text inside the show_theme_update_notice() function.

    With these steps, your custom WordPress theme will automatically check for updates and display a notice on the WordPress admin dashboard when an update is available.

Viewing 1 replies (of 1 total)
  • The topic ‘How to make a Theme Updatable’ is closed to new replies.