diff --git a/packages/block-library/src/social-link/index.php b/packages/block-library/src/social-link/index.php index 488b91b02c27de..c1f5afcba4df07 100644 --- a/packages/block-library/src/social-link/index.php +++ b/packages/block-library/src/social-link/index.php @@ -27,6 +27,14 @@ function render_block_core_social_link( $attributes, $content, $block ) { return ''; } + /** + * Prepend URL with https:// if it doesn't appear to contain a scheme + * and it's not a relative link starting with //. + */ + if ( ! parse_url( $url, PHP_URL_SCHEME ) && ! str_starts_with( $url, '//' ) ) { + $url = 'https://' . $url; + } + $rel_target_attributes = ''; if ( $open_in_new_tab ) { $rel_target_attributes = 'rel="noopener nofollow" target="_blank"';