This is a handler that turns the link (https://t.me/your-chanel/posd-id) in the content into HTML code.
Add code in your file function.php
Tested:
WordPress 6.4.2 (Classic Editor/Gutenberg Editor)
PHP 7.4
/**
* Embed register handler from Telegram post (t.me).
*
* @since 1.0.0
*/
add_action( 'init', 'wphaf_embed_register_handler_telegram' );
function wphaf_embed_register_handler_telegram() {
wp_embed_register_handler(
'telegram',
'~https://t\.me/([a-z0-9_-]+)/([0-9]+)+~im',
'wphaf_callback_embed_handler_telegram'
);
}
/**
* Callback function embed register handler from Telegram post (t.me).
*
* @since 1.0.0
*/
function wphaf_callback_embed_handler_telegram( $matches ) {
return '<script async src="https://telegram.org/js/telegram-widget.js?21" data-telegram-post="' . $matches[1] . '/' . $matches[2] . '" data-width="100%"></script>';
}