我是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' );
答案 0 :(得分:0)
试
function my_wpseo_canonical( $canonical ) {
global $post;
$attachment = get_post( $post->ID );
$protocol = ($_SERVER['HTTPS'] && $_SERVER['HTTPS'] != "off") ? "https" : "http";
$cleansed = $protocol . "://" .site_url(). $_SERVER['HTTP_HOST'];
$cleansed2 = get_permalink($attachment);
$canonical = $cleansed . $cleansed2;
return $canonical;
}