你能在wordpress中预先确定soundcloud oembed播放器的颜色吗

Can you predetermine the colour of a soundcloud oembed player in wordpress

如何在不包含十六进制颜色代码的情况下更改 soundcloud 播放器(在 wordpress 中)的颜色,在我将 soundcloud iframe 嵌入到 wordpresspost 中的每个实例中

例如 - 而不是 :

<iframe src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/104054925&amp;color=ff3366&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false" width="100%" height="166" frameborder="no" scrolling="no"></iframe>

我只想 post 一个 link 像这样:

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');

?>

例如将以下内容添加到 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;