自定义 wordpress oEmbedd (soundcloud)
Customize wordpress oEmbedd (soundcloud)
我正在使用 Wordpress 4.3.1,我注意到它使用 oEmbed 自动嵌入我来自 soundcloud 的曲目。
这太棒了!除了,我无法控制小部件的显示方式。
首先我想展示 "Classic Embed" 没有艺术作品。
其次,我希望小部件更宽。
如何在不编辑我的 wordpress 页面中每个 post 的短代码的情况下实现这一目标?
您可以添加过滤器来更改 oEmbed 代码的显示方式。以下是一些可以帮助您入门的内容:
// this function is called on all urls surrounded by the WordPress embed shortcode.
// i.e.: [embed]https://soundcloud.com/gratefuldead/grateful-dead-box-of-rain[/embed]
function my_embed_options( $code ) {
// look for SoundCloud link:
if( strpos( $code, 'soundcloud.com') !== false ) {
$code = str_replace( 'show_artwork=true', 'show_artwork=false', $code );
}
return $code;
}
add_filter( 'embed_oembed_html', 'my_embed_options' );
您可以找到 SoundCloud 播放器的完整参数列表 here。
我正在使用 Wordpress 4.3.1,我注意到它使用 oEmbed 自动嵌入我来自 soundcloud 的曲目。
这太棒了!除了,我无法控制小部件的显示方式。
首先我想展示 "Classic Embed" 没有艺术作品。
其次,我希望小部件更宽。
如何在不编辑我的 wordpress 页面中每个 post 的短代码的情况下实现这一目标?
您可以添加过滤器来更改 oEmbed 代码的显示方式。以下是一些可以帮助您入门的内容:
// this function is called on all urls surrounded by the WordPress embed shortcode.
// i.e.: [embed]https://soundcloud.com/gratefuldead/grateful-dead-box-of-rain[/embed]
function my_embed_options( $code ) {
// look for SoundCloud link:
if( strpos( $code, 'soundcloud.com') !== false ) {
$code = str_replace( 'show_artwork=true', 'show_artwork=false', $code );
}
return $code;
}
add_filter( 'embed_oembed_html', 'my_embed_options' );
您可以找到 SoundCloud 播放器的完整参数列表 here。