wordpress收费下载资源主题
wordpress付费下载资源插件

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 个评论

定制开发
本站承接WordPress等系统建站仿站、二次开发、主题插件定制等开发服务
在线咨询
  • 请直接说明需求,勿问在否
    QQ:1-247-246-247

  • QQ一群:104228692(满)
  • QQ二群:64786792
在线咨询
本站承接WordPress建站仿站、二次开发、主题插件定制等PHP开发服务!

了解详情