【问题标题】:How do I change the JSON-LD `@type` from `Article` to `NewsArticle` in WordLift如何在 WordLift 中将 JSON-LD `@type` 从 `Article` 更改为 `NewsArticle`
【发布时间】:2018-10-22 09:09:19
【问题描述】:

我想将 JSON-LD 中 WordLift 插件导出的 @type: Article 更改为 @type: NewsArticle

我该怎么做?

【问题讨论】:

    标签: wordpress json-ld wordlift


    【解决方案1】:

    您可以在将 JSON-LD 输出发送到客户端之前对其进行过滤并更改它的任何部分,例如在这种特定情况下:

    add_filter( 'wl_post_jsonld',  function( $jsonld ) {
    
      // Bail out if `@type` isn't set or isn't `Article`.
      if ( ! isset( $jsonld['@type'] ) || 'Article' !== $jsonld['@type'] ) {
        return $jsonld;
      }
    
      $jsonld['@type'] = 'NewsArticle';
    
      return $jsonld;
    } );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-29
      • 1970-01-01
      • 1970-01-01
      • 2019-10-26
      • 2012-11-25
      • 2020-10-05
      相关资源
      最近更新 更多