获取wordpress 当前网页的网址
<?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; } ?>
|
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 文件中
在page headers 调用
<?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;?>" /> // 告诉百度,那个才是移动端
|
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;?>"
/
>
/
/
告诉百度,那个才是移动端
|
加入手机进入pc 网页跳转到手机端的代码
<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
|
<
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;?>"
/
>
|
移动端加入
<?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
|
<?php
$m_url
=
curPageURL
(
)
;
$www_url
=
str_replace
(
':443'
,
''
,
str_replace
(
'm.'
,
'www.'
,
$m_url
)
)
;
?>
<
link
rel
=
"canonical"
href
=
"<?php echo $www_url;?>"
/
>
|
技术支持 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页面" >
|
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页面"
>
|
590

被折叠的 条评论
为什么被折叠?



