render_block_core_social_link() – Renders the `core/social-link` block on server.
You appear to be a bot. Output may be restricted
Description
Renders the core/social-link
block on server.
Usage
$string = render_block_core_social_link( $attributes, $content, $block );
Parameters
- $attributes
- ( Array ) required – The block attributes.
- $content
- ( String ) required – InnerBlocks content of the Block.
- $block
- ( WP_Block ) required – Block object.
Returns
string Rendered HTML of the referenced block.
Source
File name: wordpress/wp-includes/blocks/social-link.php
Lines:
1 to 58 of 58
function render_block_core_social_link( $attributes, $content, $block ) { $open_in_new_tab = isset( $block->context['openInNewTab'] ) ? $block->context['openInNewTab'] : false; $service = ( isset( $attributes['service'] ) ) ? $attributes['service'] : 'Icon'; $url = ( isset( $attributes['url'] ) ) ? $attributes['url'] : false; $label = ( isset( $attributes['label'] ) ) ? $attributes['label'] : block_core_social_link_get_name( $service ); $rel = ( isset( $attributes['rel'] ) ) ? $attributes['rel'] : ''; $show_labels = array_key_exists( 'showLabels', $block->context ) ? $block->context['showLabels'] : false; // Don't render a link if there is no URL set. if ( ! $url ) { return ''; } /** * Prepend emails with `mailto:` if not set. * The `is_email` returns false for emails with schema. */ if ( is_email( $url ) ) { $url = 'mailto:' . $url; } /** * 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; } $icon = block_core_social_link_get_icon( $service ); $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'wp-social-link wp-social-link-' . $service . block_core_social_link_get_color_classes( $block->context ), 'style' => block_core_social_link_get_color_styles( $block->context ), ) ); $link = '<li ' . $wrapper_attributes . '>'; $link .= '<a href="' . esc_url( $url ) . '" class="wp-block-social-link-anchor">'; $link .= $icon; $link .= '<span class="wp-block-social-link-label' . ( $show_labels ? '' : ' screen-reader-text' ) . '">'; $link .= esc_html( $label ); $link .= '</span></a></li>'; $processor = new WP_HTML_Tag_Processor( $link ); $processor->next_tag( 'a' ); if ( $open_in_new_tab ) { $processor->set_attribute( 'rel', esc_attr( $rel ) . ' noopener nofollow' ); $processor->set_attribute( 'target', '_blank' ); } elseif ( '' !== $rel ) { $processor->set_attribute( 'rel', esc_attr( $rel ) ); } return $processor->get_updated_html(); }