准备好更改您的分享链接了吗?在本指南中,我们将向您展示一些简单的示例,说明如何调整和个性化共享链接。主题钩子允许您添加、删除、重新排序和自定义图标。
新的分享链接
/**
* Load font-awesome icons.
*/
add_action( 'wp_enqueue_scripts', function () {
wp_enqueue_style( 'font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css', false, '6.4.2' );
} );
/**
* Change icons.
*/
add_filter( 'flatsome_share_links', function ( $links, $args ) {
$links['threads'] = array(
'enabled' => true,
'atts' => array(
'href' => 'https://www.facebook.com/sharer.php?u=' . $args['link'], // Change https://www.facebook.com/sharer.php?u= to the URL for sharing a Thread
'data-label' => 'Threads',
'onclick' => $args['on_click'],
'rel' => 'noopener noreferrer nofollow',
'target' => '_blank',
'class' => $args['classes'] . ' threads',
'title' => 'Share on Threads',
'aria-label' => 'Share on Threads',
),
'icon' => '<i class="fa-brands fa-threads"></i>',
'priority' => 5,
);
return $links;
}, 10, 2 );
css添加
/* Give the new threads share link a color */
.button.threads:not(.is-outline), .button.threads:hover {
color: #000!important;
}
更改优先级(顺序)和图标
/**
* Load font-awesome icons.
*/
add_action( 'wp_enqueue_scripts', function () {
wp_enqueue_style( 'font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css', false, '6.2.1' );
} );
/**
* Change priority (order) and icon for instagram.
*/
add_filter( 'flatsome_share_links', function ( $links, $args ) {
$links['facebook']['priority'] = 50;
$links['facebook']['icon'] = '<i class="fa-brands fa-square-facebook"></i>';
return $links;
}, 10, 2 );
删除 nofollow
/**
* Remove 'nofollow' on all share links example.
*/
add_filter( 'flatsome_share_links', function ( $links, $args ) {
foreach ( $links as $key => $link ) {
if ( empty( $link['atts']['rel'] ) ) continue;
$links[ $key ]['atts']['rel'] = implode( ' ', array_diff( explode( ' ', $link['atts']['rel'] ), array( 'nofollow' ) ) );
}
return $links;
}, 10, 2 );
禁用工具提示
/**
* Disable tooltips on all share links example.
*/
add_filter( 'flatsome_share_links', function ( $links, $args ) {
foreach ( $links as $key => $link ) {
// Remove title attribute for native tooltip.
if ( ! empty( $link['atts']['title'] ) ) {
unset( $links[ $key ]['atts']['title'] );
}
// Additionally remove tooltip class (optional).
if ( empty( $link['atts']['class'] ) ) continue;
$links[ $key ]['atts']['class'] = implode( ' ', array_diff( explode( ' ', $link['atts']['class'] ), array( 'tooltip' ) ) );
}
return $links;
}, 10, 2 );
要求
3.17.0 或更高版本