Jetpack: Use Photon in your Text widgets

in WordPress

By default, Photon is only applied to your post content. There are ways to use Photon within your theme too, but if you want all images from your Text Widget to be cached with Photon, you can use this code snippet:

function jeherve_photonize_text_widget_images( $content ) {
	if ( class_exists( 'Jetpack_Photon' ) ) {
		$content = Jetpack_Photon::filter_the_content( $content );
	}

	return $content;
}
add_filter( 'widget_text', 'jeherve_photonize_text_widget_images' );