子比主题文章分享按钮增强

效果图

注意

仅手机端可以使用此功能 不是手机端将显示默认分享模拟框

部分浏览器不支持此功能 我仅测试过苹果默认浏览器 更多需自行测试 介意误购!!!

代码

functions.php代码

//分享按钮增强
function isSupportedBrowser() 
{
    // 获取浏览器 User Agent
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    
    // 判断 User Agent 中是否包含移动设备的标识
    if (preg_match('/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i', $user_agent)) 
    {
        return true;
    } else {
        return false;
    }
    // 检查 User Agent 是否包含常见的现代浏览器标识
    $supported_browsers = array(
        'Firefox',
        'Chrome',
        'Safari',
        'Opera',
        'Edge'
    );
    $browser_supported = false;
    foreach ($supported_browsers as $browser) {
        if (stripos($user_agent, $browser) !== false) {
            $browser_supported = true;
            break;
        }
    }
    return $browser_supported;
}

/wp-content/themes/zibll/inc/functions/zib-footer.php代码

搜索

 
$btn .= zib_get_post_share_btn($post, ‘tabbar-item single-action-tabbar’);

将其替换为:

 
 
 
//ZYX-分享按钮增强
$postTitle = get_the_title($post_id);
 
$link_title = $postTitle . zib_get_delimiter_blog_name();
 
if (isSupportedBrowser()) {
$btn .= ‘<a class=”tabbar-item single-action-tabbar” target=”_blank” title=”分享” onclick=”navigator.share({ title: \” . $link_title . ‘\’, url: \” . $url . ‘\’ })”><icon><svg class=”icon” aria-hidden=”true”><use xlink:href=”#icon-share”></use></svg></icon><text>分享<text></text></text></a>’;
} else {
$btn .= zib_get_post_share_btn($post, ‘tabbar-item single-action-tabbar’);
}
// $btn .= zib_get_post_share_btn($post, ‘tabbar-item single-action-tabbar’);

/wp-content/themes/zibll/inc/functions/zib-single.php代码

搜索

 
 
 
echo zib_get_post_share_btn(null, ‘action action-share’);

将其替换为:

 
 
 
//ZYX-分享按钮增强
$post_id = get_the_ID();
 
$postTitle = get_the_title($post_id);
 
$link_title = $postTitle . zib_get_delimiter_blog_name();
 
if (isSupportedBrowser()) {
echo ‘<a class=”hover-show dropup action action-share” target=”_blank” title=”分享” onclick=”navigator.share({ title: \” . $link_title . ‘\’, text: \” . $link_title . ‘\’, url: \” . $url . ‘\’ })”><icon><svg class=”icon” aria-hidden=”true”><use xlink:href=”#icon-share”></use></svg></icon><text>分享<text></text></text></a>’;
} else {
echo zib_get_post_share_btn(null, ‘action action-share’);
}

 

本文链接:
文章作者
HAC 社区
隐私政策
PrivacyPolicy
用户协议
UseGenerator
许可协议
NC-SA 4.0
© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容