在我将wordcloud iframe嵌入wordpress中的帖子的每个实例中,如何在不必包含十六进制颜色代码的情况下更改soundcloud播放器的颜色(在wordpress中)
例如 - 而不是:
<iframe src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/104054925&color=ff3366&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false" width="100%" height="166" frameborder="no" scrolling="no"></iframe>
我想发布一个类似的链接:
https://soundcloud.com/banksbanksbanks/banks-waiting-game-prod-by
以某种方式在wordpress主题中预先确定了播放器的颜色(例如#ff3366)
我是否具有相同的灵活性来自定义播放器,就像使用youtube嵌入一样。例如,youtube自定义不会在带有以下代码的视频上显示标题。
add_filter('embed_oembed_html', 'my_embed_oembed_html', 99, 4);
function my_embed_oembed_html($html, $url, $attr, $post_id) {
return '<div class="entry-embed">' . $html . '</div>';
}
function iweb_modest_youtube_player( $html, $url, $args ) {
return str_replace( '?feature=oembed', '?
feature=oembed&modestbranding=1&showinfo=0&rel=0&HD=1', $html );
}
add_filter( 'oembed_result', 'iweb_modest_youtube_player', 10, 3 );
add_filter('embed_handler_html', 'custom_youtube_settings');
add_filter('embed_oembed_html', 'custom_youtube_settings');
?>
答案 0 :(得分:1)
作为示例,将函数添加到functions.php
的底部 //Add soundcloud as oembed provider
wp_oembed_add_provider( 'http://soundcloud.com/*', 'http://soundcloud.com/oembed' );
//function to adjust colors and options
function soundcloud_theme_embed($html, $url, $attr) {
//Change the color here and adjust the options based on //https://developers.soundcloud.com/docs/oembed#introduction
$url = $url.'?iframe=true&maxheight=150&show_comments=false&color=ff3366';
//get the udated url so you only have to type https://soundcloud.com/banksbanksbanks/banks-waiting-game-prod-by into content
$embed_code= wp_oembed_get($url);
//turn off visuals so you can see the color change
$newHtml= str_replace( '?visual=true', '?visual=false', $embed_code );
//replace output with newly created output
$html=$newHtml;
return $html;
}
//add your function to the fitler https://wordpress.org/support/topic/hookfilter-for-auto-embed-function-of-wp
add_filter( 'embed_oembed_html', 'soundcloud_theme_embed', 10, 4 ) ;
您可以按照here
列出的文档为主题中的颜色添加选项例如,您可以更改此行,以便颜色是变量并从主题中读取,或者您可以调整代码并创建插件,在那里添加选项
$url = $url.'?iframe=true&maxheight=150&show_comments=false&color=ff3366';
会变成
$url = $url.'?iframe=true&maxheight=150&show_comments=false&color='.$themeColor;