从 WordPress oembed json 链接中删除author和author_url

use*_*473 4 wordpress oembed

我注意到 WordPress 在标题中生成了 2 个链接。它们包含一些 oembed 参数。

这看起来像这样:

<link rel="alternate" type="application/json+oembed" href="......">
<link rel="alternate" type="text/xml+oembed" href=".......">

{
      "version": "1.0",
      "provider_name": "Website Name",
      "provider_url": "http://example.com",
      "author_name": "admin",
      "author_url": "http://example.com/author/admin/",
      "title": "",
      "type": "rich",
      "width": 600,
      "height": 338,
      "html": "long string of html"
    }
Run Code Online (Sandbox Code Playgroud)

我知道我可以禁用这些链接,但我想保留它们并仅删除author_name 和author_url。

我有办法做到这一点吗?

我希望你能帮忙。

谢谢。

小智 5

保留rel链接并过滤数组数据:

function filter_oembed_response_data_author( $data, $post, $width, $height ) {
    //print_r($data);
    unset($data['author_name']);
    unset($data['author_url']);
    return $data;
};
add_filter( 'oembed_response_data', 'filter_oembed_response_data_author', 10, 4 );
Run Code Online (Sandbox Code Playgroud)

您可以转到 rel 链接之一,取消注释 print_r 并操作 $data 数组以添加、编辑或删除条目。