我正试图探索在我的网站上嵌入视频的新方法,因为我的一些贡献者在使用预览功能时难以查看flash嵌入。
理想情况下,通过[嵌入]短码使用oEmbed是最简单的,但我遇到了一个似乎无法找到解决方案的问题。
我知道您可以通过“媒体”选项卡指定嵌入的最大尺寸,但这不是我想要做的。为了保持连续性,我们网站上显示的每一张照片或视频都是560像素x 340像素,这些都是我想强制添加到Oembed上的尺寸,但我找不到方法!
在这里寻找帮助,因为谷歌已经没有用了!
我正试图探索在我的网站上嵌入视频的新方法,因为我的一些贡献者在使用预览功能时难以查看flash嵌入。
理想情况下,通过[嵌入]短码使用oEmbed是最简单的,但我遇到了一个似乎无法找到解决方案的问题。
我知道您可以通过“媒体”选项卡指定嵌入的最大尺寸,但这不是我想要做的。为了保持连续性,我们网站上显示的每一张照片或视频都是560像素x 340像素,这些都是我想强制添加到Oembed上的尺寸,但我找不到方法!
在这里寻找帮助,因为谷歌已经没有用了!
当你指的是使用oEmbed代码时,我假设你指的是WordPress能够获取媒体的URL(比如YouTube上的URL)和automatically embed 把它放到一个帖子里。
如果是这样,那么您可以利用embed_oembed_html
WordPress提供的挂钩。
以下是使用自定义函数的方法:
function example_custom_oembed_dimensions($html, $url, $args) {
// Set the height of the video
$height_pattern = "/height=\\"[0-9]*\\"/";
$html = preg_replace($height_pattern, "height=\'560\'", $html);
// Set the width of the video
$width_pattern = "/width=\\"[0-9]*\\"/";
$html = preg_replace($width_pattern, "width=\'340\'", $html);
// Now return the updated markup
return $html;
} // end example_custom_oembed_dimensions
add_filter(\'embed_oembed_html\', \'example_custom_oembed_dimensions\', 10, 3);
您提到您在整个站点中使用一致的媒体宽度和高度,但您对使用媒体设置页面不感兴趣。为了保持一致性,您可以通过编程强制媒体设置中的值,并在整个工作过程中在过滤器中使用这些值。
例如,首先我们需要设置媒体大小:
function example_force_media_size() {
if(get_option(\'embed_size_w\') != 560) {
update_option(\'embed_size_w\', 560);
} // end if
if(get_option(\'embed_size_h\') != 340) {
update_option(\'embed_size_h\', 340);
} // end if
} // end example_force_media_size
add_action(\'init\', \'example_force_media_size\');
现在,每当有人试图覆盖“媒体设置”页面中的这些设置时,此函数都会启动并强制执行这些值。接下来,您可以检索这些值,然后在嵌入媒体时使用它们:
function example_custom_oembed_dimensions($html, $url, $args) {
// Find the height value, replace it with Media Settings value
$height_pattern = "/height=\\"[0-9]*\\"/";
$height = get_option(\'embed_size_h\');
$html = preg_replace($height_pattern, "height=\'$height\'", $html);
// Find the width value, replace it with Media Settings value
$width_pattern = "/height=\\"[0-9]*\\"/";
$width = get_option(\'embed_size_w\');
$html = preg_replace($width_pattern, "width=\'$width\'", $html);
// Now return the updated markup
return $html;
} // end example_custom_oembed_dimensions
add_filter(\'embed_oembed_html\', \'example_custom_oembed_dimensions\', 10, 3);
第一个功能可能是您所需要的全部功能,但强制设置介质设置的值也可以使围绕其他类型的介质编写自定义过滤器变得更容易。如果你想嵌入flash视频,你应该试试kimili falsh embed 插件。。使嵌入flash变得更容易,并更容易控制大小等。
嘿,伙计们,当在后端(帖子或页面)发布youtube视频链接时,wordpress会自动为我创建嵌入代码。是否可以添加过滤器?我想将所有嵌入视频的宽度和高度更改为100%?e、 g。<object width=\"100%\" height=\"100%\"> <param name=\"movie\" value=\"http://www.youtube.com/v/rBa5qp9sUOY?version=3\"> <param name=\"allowFu