【发布时间】:2017-03-08 12:06:01
【问题描述】:
我是 php 新手。 我正在使用 Wordpress 和 yoast。
但是,yoast 插件没有正确编写规范。我希望编写规范以便它使用语法
<link rel="canonical" href="https://www.travelideology.com/about/">
不过是写
<link rel="canonical" href="https:/about/">
如果有人能告诉我我的代码有什么问题,我会很高兴。
代码如下:
function my_wpseo_canonical( $canonical ) {
global $post;
$attachment = get_post( $post->ID );
$protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http";
$cleansed = $protocol . "://" . $_SERVER['HTTP_HOST'];
$cleansed2 = get_permalink($attachment);
$canonical = $cleansed . $cleansed2;
return $canonical;
}
add_filter( 'wpseo_canonical', 'my_wpseo_canonical' );
【问题讨论】:
标签: php url dns canonical-link