禁止使用模板插件做违法内容(涉黄等),否则将受到法律的制裁。

WordPress hook钩子embed_cache_oembed_types的用法详解

禁止使用模板插件做违法内容(涉黄等),否则将受到法律的制裁。

WordPress中的钩子(hook)是一种用于将自定义代码插入到特定位置的机制。其中一个常用的钩子是`embed_cache_oembed_types`,它可以用于修改WordPress中oEmbed支持的嵌入类型。

`embed_cache_oembed_types`的定义如下:`apply_filters( 'embed_cache_oembed_types', array( 'post', 'page', 'attachment' ) )`。它允许我们通过添加或移除嵌入类型来修改oEmbed的功能。

以下是`embed_cache_oembed_types`的用法详解:

1. 添加新的嵌入类型:

function custom_embed_types( $types ) {
$types[] = 'custom_type';
return $types;
}
add_filter( 'embed_cache_oembed_types', 'custom_embed_types' );

在这个例子中,我们添加了一个名为`custom_type`的新嵌入类型。

2. 移除现有的嵌入类型:

function remove_embed_types( $types ) {
$key = array_search( 'attachment', $types );
if ( false !== $key ) {
unset( $types[ $key ] );
}
return $types;
}
add_filter( 'embed_cache_oembed_types', 'remove_embed_types' );

在这个例子中,我们移除了默认的`attachment`嵌入类型。

3. 修改现有的嵌入类型:

function modify_embed_types( $types ) {
$types[] = 'custom_type';
$key = array_search( 'attachment', $types );
if ( false !== $key ) {
$types[ $key ] = 'new_attachment_type';
}
return $types;
}
add_filter( 'embed_cache_oembed_types', 'modify_embed_types' );

在这个例子中,我们添加了一个新的嵌入类型`custom_type`,同时将默认的`attachment`嵌入类型重命名为`new_attachment_type`。

通过使用`embed_cache_oembed_types`钩子,我们可以对oEmbed功能进行自定义,以满足特定的需求。

0 个评论

 
联系
目前暂停一切业务,客服消息可能不会及时回复,谢谢理解。
在线咨询
    在线咨询
    禁止使用模板插件做违法内容(涉黄等),否则将受到法律的制裁。