The get_theme_update_available() WordPress PHP function retrieves the update link if there is a theme update available.
Usage
get_theme_update_available( $theme );
Input: $theme
– A WP_Theme object
Output: Returns the update link or false
if no update is available.
Parameters
$theme
(WP_Theme) – Required. The WP_Theme object to check for updates.
More information
See WordPress Developer Resources: get_theme_update_available()
Examples
Check if a theme update is available
This example checks if a theme update is available for the current theme.
$current_theme = wp_get_theme(); $update_link = get_theme_update_available( $current_theme ); if ( $update_link ) { echo "Update available: " . $update_link; } else { echo "No update available."; }
Display update link for all installed themes
This example loops through all installed themes and displays the update link if an update is available.
$themes = wp_get_themes(); foreach ( $themes as $theme ) { $update_link = get_theme_update_available( $theme ); if ( $update_link ) { echo $theme->get( 'Name' ) . " update available: " . $update_link . "<br>"; } else { echo $theme->get( 'Name' ) . " - No update available.<br>"; } }
Show update notification for a specific theme
This example checks if a specific theme (e.g., “Twenty Twenty-One”) has an update available and shows a notification message.
$theme_name = "Twenty Twenty-One"; $theme = wp_get_theme( $theme_name ); $update_link = get_theme_update_available( $theme ); if ( $update_link ) { echo "Update available for " . $theme_name . ": " . $update_link; } else { echo "No update available for " . $theme_name . "."; }
Display update links for parent and child themes
This example checks if a child theme and its parent theme have updates available and displays the update links.
$child_theme = wp_get_theme(); $parent_theme = $child_theme->parent(); $update_link_child = get_theme_update_available( $child_theme ); $update_link_parent = $parent_theme ? get_theme_update_available( $parent_theme ) : false; echo "Child theme: " . $child_theme->get( 'Name' ) . "<br>"; if ( $update_link_child ) { echo "Update available: " . $update_link_child . "<br>"; } else { echo "No update available.<br>"; } if ( $parent_theme ) { echo "Parent theme: " . $parent_theme->get( 'Name' ) . "<br>"; if ( $update_link_parent ) { echo "Update available: " . $update_link_parent . "<br>"; } else { echo "No update available.<br>"; } } else { echo "No parent theme.<br>"; }