我是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' );发布于 2016-10-26 16:15:50
试一试
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;
}https://stackoverflow.com/questions/40256932
复制相似问题