【问题标题】:php for full url yoast用于完整 url yoast 的 php
【发布时间】: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


    【解决方案1】:

    试试

    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; 
        }
    

    【讨论】:

    • 也可以试试 home_url()
    猜你喜欢
    • 1970-01-01
    • 2011-07-31
    • 2013-05-28
    • 2011-10-09
    • 1970-01-01
    • 2011-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多