如何通过使用oEmbed将SoundCloud嵌入WordPress帖子中

One of our users asked us for an easy way to embed SoundCloud in their WordPress site. WordPress has this cool feature called oEmbed which supports auto-embedding as long as you post the URL in its own line. Currently the WordPress oEmbed library supports popular services like Youtube, Twitter, Vimeo, etc. However, SoundCloud is not supported by WordPress just yet. Well there is nothing to worry because WordPress makes it really easy to add oEmbed providers using wp_oembed_add_provider() function. In this article, we will show you how to add oEmbed support for SoundCloud in WordPress.

我们的一位用户向我们询问了一种将SoundCloud嵌入其WordPress网站的简便方法。 WordPress具有称为oEmbed的这一很酷的功能,只要您在自己的行中发布URL, 它就支持自动嵌入。 当前,WordPress oEmbed库支持流行的服务,如Youtube,Twitter, Vimeo等。但是,WordPress尚不支持SoundCloud。 没什么可担心的,因为WordPress使得使用wp_oembed_add_provider()函数添加oEmbed提供程序非常容易。 在本文中,我们将向您展示如何在WordPress中添加对SoundCloud的oEmbed支持。

Update: You DO NOT have to use this tutorial anymore. WordPress 3.5+ has built-in oEmbed support for SoundCloud.

更新:您不必再使用本教程。 WordPress 3.5+具有对SoundCloud的内置oEmbed支持。

All you have to do is paste the following code in your theme’s functions.php file or in a site-specific plugin.

您所要做的就是将以下代码粘贴到主题的functions.php文件或特定于站点的插件中 。


// Add SoundCloud oEmbed
function add_oembed_soundcloud(){
wp_oembed_add_provider( 'http://soundcloud.com/*', 'http://soundcloud.com/oembed' );
}
add_action('init','add_oembed_soundcloud');

That’s it. Simply paste your SoundCloud URL in a separate line and let the auto-embedding (oEmbed) magic do the rest.

而已。 只需将您的SoundCloud URL粘贴在单独的一行中,然后让自动嵌入(oEmbed)魔术完成其余的工作。

There is a fairly popular plugin that you can use as well called SoundCloud is Gold which offers a lot of features. Alternatively because SoundCloud is officially supported by WordPress.com, there is a shortcode available for all WordPress.com users. So you can use the JetPack plugin for self-hosted WordPress and enable shortcode embeds option. Once you do that, you will be able to use the shortcode like this:

您可以使用一个相当流行的插件,即SoundCloud is Gold ,它提供了许多功能。 另外,由于WordPress.com 正式支持 SoundCloud,因此所有WordPress.com用户都可以使用短代码。 因此,您可以将JetPack插件用于自托管的WordPress,并启用简码嵌入选项。 完成后,您将可以使用如下所示的短代码:

[soundcloud url=”http://api.soundcloud.com/tracks/207988″ iframe=”true” /]

[soundcloud url =“ http://api.soundcloud.com/tracks/207988” iframe =“ true” /]

Hopefully this will help anyone who is looking for a way to embed SoundCloud in WordPress.

希望这将对正在寻找将SoundCloud嵌入WordPress的任何人的帮助。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-embed-soundcloud-in-your-wordpress-posts-by-using-oembed/

你可能感兴趣的:(java,php,小程序,wordpress,javascript,ViewUI)