wpscholar/wp-结构化视频数据

WordPress 中视频嵌入的结构化数据。

1.0 2019-05-28 15:41 UTC

This package is auto-updated.

Last update: 2024-08-29 05:00:37 UTC


README

WordPress 中视频嵌入的结构化数据。

不熟悉结构化数据?请查看这些资源

要求

PHP 5.6+ WordPress 4.8+

先决条件

安装 Composer

安装

  • 通过 Composer 将模块添加到您的 WordPress 插件或主题项目中
composer require wpscholar/wp-structured-video-data
  • 确保您已将 Composer 自动加载器添加到项目中
require __DIR__ . '/vendor/autoload.php';

使用方法

默认情况下,WordPress 中的所有视频嵌入将自动注入适当的结构化数据。

高级使用

如果您想用于WordPress内容之外的具体视频URL

<?php

$videoUrl = 'https://www.youtube.com/watch?v=V9I1-c9o1LM';
$embed = wp_oembed_get( $videoUrl );
$structuredData = new \wpscholar\WordPress\StructuredVideoData( $videoUrl );
echo $structuredData->render( $embed ); // For JSON-LD format

// OR

echo $structuredData->renderAsMicrodata( $embed ); // For Microdata format

请注意,您还需要负责渲染视频嵌入。这可以通过 wp_oembed_get() 实现。