render_block_core_social_link() WP 1.0
Renders the core/social-link block on server.
No Hooks.
Return
String. Rendered HTML of the referenced block.
Usage
render_block_core_social_link( $attributes, $content, $block );
- $attributes(array) (required)
- The block attributes.
- $content(string) (required)
- InnerBlocks content of the Block.
- $block(WPBlock) (required)
- Block object.
Code of render_block_core_social_link() render block core social link WP 5.6.2
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 );
$class_name = isset( $attributes['className'] ) ? ' ' . $attributes['className'] : false;
// Don't render a link if there is no URL set.
if ( ! $url ) {
return '';
}
$attribute = '';
if ( $open_in_new_tab ) {
$attribute = 'rel="noopener nofollow" target="_blank"';
}
$icon = block_core_social_link_get_icon( $service );
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'wp-social-link wp-social-link-' . $service . $class_name ) );
return '<li ' . $wrapper_attributes . '><a href="' . esc_url( $url ) . '" aria-label="' . esc_attr( $label ) . '" ' . $attribute . '> ' . $icon . '</a></li>';
}