diff --git a/packages/block-library/src/social-link/index.php b/packages/block-library/src/social-link/index.php index c4f78f5dc4e11..753b84f90d935 100644 --- a/packages/block-library/src/social-link/index.php +++ b/packages/block-library/src/social-link/index.php @@ -45,6 +45,15 @@ function render_block_core_social_link( $attributes, $content, $block ) { ) ); + // Add default https if no protocol specified. The following chunk of code + // is taken from esc_url which is hard-coded to use http. This can be + // changed to pass the parameter in esc_url after + // https://core.trac.wordpress.org/ticket/52886 is in core. + if ( strpos( $url, ':' ) === false && ! in_array( $url[0], array( '/', '#', '?' ), true ) && + ! preg_match( '/^[a-z0-9-]+?\.php/i', $url ) ) { + $url = 'https://' . $url; + } + return '
  • ' . $icon . '
  • '; }