【问题标题】:Invalid HTML code generated by WordPress (<link rel='https://api.w.org/'...)WordPress 生成的无效 HTML 代码 (<link rel='https://api.w.org/'...)
【发布时间】:2021-08-04 05:25:54
【问题描述】:

WordPress 5.2.4

我正在尝试获取有效的 HTML。

验证器 (https://validator.w3.org/) 显示:

错误:元素链接上属性 rel 的错误值 https://api.w.org/: 字符串https://api.w.org/ 不是注册关键字。

从第 135 行第 1 列开始;到第 135 行,第 60 列

↩https://api.w.org/' href='http://ved/wp-json/' />↩

问题似乎出在 wp-includes/rest-api.php 第 841 行:

function rest_output_link_wp_head() {
    $api_root = get_rest_url();

    if ( empty( $api_root ) ) {
        return;
    }

    echo "<link rel='https://api.w.org/' href='" . esc_url( $api_root ) . "' />\n"; // Line 841.
}

嗯,这似乎是 WordPress 的核心。但它会呈现无效代码。

你帮我解决这两个问题: 1. 处理这个问题最正确和优雅的方法是什么? 2. 这里有什么需要考虑的地方。我的意思是我似乎不会使用 REST API,但也许有些插件需要 REST API。

【问题讨论】:

    标签: wordpress


    【解决方案1】:
    // Disable REST API link tag
    remove_action('wp_head', 'rest_output_link_wp_head', 10);
    
    // Disable oEmbed Discovery Links
    remove_action('wp_head', 'wp_oembed_add_discovery_links', 10);
    
    // Disable REST API link in HTTP headers
    remove_action('template_redirect', 'rest_output_link_header', 11, 0);
    

    尝试在function.php中加入以上代码

    【讨论】:

      【解决方案2】:

      删除 rest_output_link_wp_head() 将使您的主题无效,以防您想将其提交到 wordpress.org。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-12-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-24
        相关资源
        最近更新 更多