简体   繁体   English

如何为移动网站社交按钮使用桌面版本页面网址

[英]How to use desktop version page url, for mobile site social buttons

I want to use social buttons on my website's mobile version. 我想在网站的移动版本上使用社交按钮。 But the issue i am facing is getting them to use url of desktop version page. 但是我面临的问题是让他们使用桌面版本页面的url。

Lets say i have a page "m.domain.com/some-page" with the desktop version url "domain.com/some-page". 假设我有一个页面“ m.domain.com/some-page”,桌面版本的网址为“ domain.com/some-page”。 When i load social buttons they don't show the count that exist for the same page's desktop url. 当我加载社交按钮时,它们不会显示同一页面的桌面URL所存在的计数。

The share count is getting spread accross mobile and desktop version at present. 目前份额数已遍及移动和台式机版本。

I use a php file to lazy load the buttons. 我使用一个php文件来延迟加载按钮。 Here is the snippet of file header which is followed by buttons scripts: 这是文件头的代码段,其后是按钮脚本:

<?php
$permalink = "http://domain.com" . $_SERVER['REQUEST_URI'];
$title = $_GET['title'] ? $_GET['title'] : $_POST['title'];
?>

But this is not giving me the expected result. 但这并没有给我预期的结果。 The code calling this file is: 调用该文件的代码是:

<script type="text/javascript">
function get_share_buttons(permalink,title){
    var url = 'http://m.domain.com/folder/shareButtons.php';
    $('#share-buttons').load(url,{permalink:permalink,title:title});
}
$(window).bind("load", function() {
    get_share_buttons('<?php the_permalink() ?>','<?php the_title(); ?>');
});
</script>

Please suggest me a solution to my problem. 请为我提出解决方案。 Thanks. 谢谢。

If you submit the mobile URL ( m.example.com ) for your social links, you will make desktop users click on the mobile URLs. 如果您为社交链接提交移动URL( m.example.com ),则将使桌面用户单击移动URL。 And, like you said, the link statistics will count mobile and desktop domains distinctively. 而且,就像您说的那样,链接统计信息将分别计算移动和桌面域。

Better use a universal domain for all external links. 最好对所有外部链接使用通用域。 Usually, this will be the "desktop" version, eg www.example.com . 通常,这将是“桌面”版本,例如www.example.com

In your html head of the mobile version, add a rel="canonical" tag that points to the desktop version. 在移动版本的html头中,添加指向桌面版本的rel="canonical"标签。 Use the desktop version URL for all social button links. 将桌面版本URL用于所有社交按钮链接。

<link rel="canonical" href="http://www.example.com/"/>

For the visitors (and search engines) visiting the universal/desktop URL, add a rel="alternate" tag on the desktop version that points to the mobile version. 对于访问通用/桌面URL的访问者(和搜索引擎),在桌面版本上添加指向移动版本的rel="alternate"标签。 You can add device detection by using CSS media queries here: 您可以在此处使用CSS媒体查询来添加设备检测:

<link rel="alternate" href="http://m.example.com" media="only screen and (max-width: 1080px)"/>

You can also add further device detection that redirects or offers a link to the mobile version if a mobile device is detected. 您还可以添加进一步的设备检测,如果检测到移动设备,该设备重定向或提供指向移动版本的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM