文章目录
获取wordpress 当前网页的网址
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<?php // 说明:获取完整URL function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; } $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; } return $pageURL; } ?> |
上面的函数放入 functions.php 文件中
![WordPress获取PC端对应的移动端的网址[wordpress 移动站改造]-园艺资材批发美乐棵,奥绿肥,花多多,赤玉土,品式泥炭](https://images.168seo.cn/blog/2018-05-27-032753.png)
在page headers 调用
1 2 3 4 5 6 7 8 |
<?php $www_url = curPageURL(); // 获取当前pc的url $m_url = str_replace(':443','',str_replace('www','m',$www_url)); // 获取对应的手机端url ?> <meta name="mobile-agent" content="format=html5;url=<?php echo $m_url;?>" /> // 告诉百度,那个才是移动端 |
![WordPress获取PC端对应的移动端的网址[wordpress 移动站改造]-园艺资材批发美乐棵,奥绿肥,花多多,赤玉土,品式泥炭](https://images.168seo.cn/blog/2018-05-27-033035.png)
加入手机进入pc 网页跳转到手机端的代码
1 2 3 |
<link rel="alternate" media="only screen and(max-width:640px)" href="<?php echo $m_url;?>"/> <link rel="alternate" media="handheld" href="<?php echo $m_url;?>" /> |
移动端加入
1 2 3 4 5 |
<?php $m_url = curPageURL(); $www_url = str_replace(':443','',str_replace('m.','www.',$m_url)); ?> <link rel="canonical" href="<?php echo $www_url;?>" /> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
技术支持 1. META标记 <meta name="mobile-agent"content="format=[wml|xhtml|html5]; url=url"> Meta声明示例: 站长需要将Meta声明放在PC页源代码内部,如下: <meta name="mobile-agent" content="format=html5;url=“pc页面对应的移动页面” > <meta name="mobile-agent" content="format=html5;url=http://m.xxx.com/"> 2. 跳转适配规则 鉴于移动化大潮的汹涌和H5页的炫丽普及,百度针对PC页与H5页的跳转适配方式推出了最优方案:在pc版网页上,添加指向对应移动版网址的特殊链接rel="alternate"标记,这有助于百度发现网站的移动版网页所在的位置;同时在移动版网页上,添加指向对应pc版网址的链接rel="canonical"标记。 例如: pc版网址:http://www.example.com/page-1 移动版网址:http://m.example.com/page-1 那么此示例中的注释如下所示: 在pc版网页(http://www.example.com/page-1) 上,添加: <link rel="alternate" media="only screen and(max-width: 640px)" href="http://m.example.com/page-1" > 注意:640px是百度,及谷歌给的参考值 在移动版网页(http://m.example.com/page-1) 上,所需的注释应为: <link rel="canonical" href="http://www.example.com/page-1" > ------网站转码--------- 在 pc 移动端 head添加 <meta name="mobile-agent" content="format=html5;url="pc页面对应的移动页面" > <link rel="alternate" media="only screen and(max-width: 640px)" href="pc页面对应的移动页面" > <meta name="applicable-device"content="pc"> <meta http-equiv="Cache-Control" content="no-transform" /> <meta http-equiv="Cache-Control" content="no-siteapp" /> 移动端添加 <meta name="applicable-device"content="mobile"> <meta http-equiv="Cache-Control" content="no-transform" /> <meta http-equiv="Cache-Control" content="no-siteapp" /> <link rel="canonical" href="移动端对于pc页面" > |

请教一下,针对移动端做了单独的地址的话,哪怎么才同步PC端的数据?不能做了移动端,还要针对移动端每次添加数据吧?
你用同一个数据库,两套模板,一套移动端一套pc端就可以了
作者您好,我现在网站是自响应的,目前新做了移动主题,能否实现同一个网站用同一个数据库,识别跳转不同主题,移动端自动跳转到M.XX.COM域名?
你可以用手机识别下我的网站就是这样的形式?是可以做到的