PHP WordPress - Make SoundCloud oEmbed Responsive

<?php add_filter( 'embed_oembed_html', 'embed_oembed_html_responsive_soundcloud', 10, 4 ); /** * Filter the cached oEmbed HTML. * * @param mixed $cache The cached HTML result, stored in post meta. * @param string $url The attempted embed URL. * @param array $attr An array of shortcode attributes. e.i. ['width'=>500,'height'=>750] * @param int $post_ID Post ID. * * @return string */ function embed_oembed_html_responsive_soundcloud( $cache, $url, $attr, $post_ID ) { if ( false !== strpos( $cache, 'soundcloud' ) ) { // replace width attribute for 100% width $cache = str_replace( 'width="' . $attr[ 'width' ] . '"', 'width="100%"', $cache ); } return $cache; } // TEST echo wp_oembed_get ('https://soundcloud.com/paradox-hh/luke-francis-brainwash-fm-jan-16th-2016');

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.