Можете ли вы заранее определить цвет проигрывателя Soundcloud в WordPress

Как я могу изменить цвет проигрывателя soundcloud (в WordPress) без необходимости включать шестнадцатеричный цветовой код, в каждом случае, когда я вставляю iframe Soundcloud в сообщение в WordPress

Например — вместо:

<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>

Я хотел бы просто опубликовать ссылку так:

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

?>

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

Вы можете добавить опцию для цвета в теме, следуя изложенной документации Вот

Например, вы бы изменили эту строку, чтобы цвет был переменной, и прочитали ее из темы, или вы можете настроить код и создать плагин, добавив туда параметры

    $url = $url.'?iframe=true&maxheight=150&show_comments=false&color=ff3366';

станет

    $url = $url.'?iframe=true&maxheight=150&show_comments=false&color='.$themeColor;
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector