admin管理员组文章数量:1287272
One of my sites is used as a personal diary with >5000 videos uploaded within the media library.
Each post uses the following shortcode, disabling pre-load and assigning a manual poster. This reduces server load and speed for the default preload='metadata', should the post contain lots of videos. The posters are manually uploaded.
[video preload="none" mp4="/wp-content/Videos/001.mp4" poster="/wp-content/Pictures/Posters/001.mp4.jpg"][/video]
This works great for posts, however; should I view videos via their tags through the archive, it displays via the default settings as found in /wp-includes/media.php which uses the standard preload='metadata'.
My question: "Is there a way to set the default 'poster' to "/wp-content/Pictures/Posters/filename.mp4.jpg" So, taking the name of the video, prepending with "/wp-content/Pictures/Posters/" and then appending with ".jpg" ?
Any help would be greatly appreciated.
One of my sites is used as a personal diary with >5000 videos uploaded within the media library.
Each post uses the following shortcode, disabling pre-load and assigning a manual poster. This reduces server load and speed for the default preload='metadata', should the post contain lots of videos. The posters are manually uploaded.
[video preload="none" mp4="/wp-content/Videos/001.mp4" poster="/wp-content/Pictures/Posters/001.mp4.jpg"][/video]
This works great for posts, however; should I view videos via their tags through the archive, it displays via the default settings as found in /wp-includes/media.php which uses the standard preload='metadata'.
My question: "Is there a way to set the default 'poster' to "/wp-content/Pictures/Posters/filename.mp4.jpg" So, taking the name of the video, prepending with "/wp-content/Pictures/Posters/" and then appending with ".jpg" ?
Any help would be greatly appreciated.
Share Improve this question asked Oct 7, 2021 at 18:18 helpless_foolhelpless_fool 111 bronze badge 1- Welcome to WPSE. Interesting problem. The tag archive should fire like any other and run a taxonomy query that can be filtered (pre_get_posts?) but the video output is what you wish to modify, not the query. I am not familiar with how WP outputs video but I would start with reading through the WP core to see how that happens. My guess is you will find a filter or action that allows you to modify attributes. – jdm2112 Commented Oct 7, 2021 at 19:04
2 Answers
Reset to default 0Thanks for your help. Managed to figure out a temporary solution, should anyone else have a similar query.
Temporarily edited media.php
$filename = basename( wp_get_attachment_url( $attachment_id ) );
$default_types = wp_get_video_extensions();
$defaults_atts = array(
'src' => '',
'poster' => "diary/wp-content/Pictures/posters/".$filename.".jpg'",
'loop' => '',
'autoplay' => '',
'preload' => 'none',
'width' => 640,
'height' => 360,
'class' => 'wp-video-shortcode',
);
I've stripped the url from the wp_get_attachment_url() attachment and plopped it directly into the 'poster' attribute.
Next, I'll have to figure out a way of writing it as a function, rather than edit media.php on every update :)
My question: "Is there a way to set the default 'poster' to "/wp-content/Pictures/Posters/filename.mp4.jpg" So, taking the name of the video, prepending with "/wp-content/Pictures/Posters/" and then appending with ".jpg" ?
To avoid editing core files, we can override the empty video shortcode poster attribute with e.g. this filter:
add_filter( 'shortcode_atts_video', function( $out, $pairs, $atts ){
// Do nothing for non-empty poster.
if ( ! empty( $atts['poster'] ) ) {
return $out;
}
// Override empty poster.
$filename = basename( $atts['src'] );
if ( ! empty( $filename ) ) {
$out['poster'] = sprintf(
content_url ( 'Pictures/Posters/%s.jpg' ), // <-- Adjust to your needs!
$filename
);
}
return $out;
}, 10, 3 );
One could also try adding a file_exists
check to make sure the default one exists.
本文标签: functionsAutomatically assign video 39poster39 value to 39filename39 for archive listing
版权声明:本文标题:functions - Automatically assign video 'poster' value to 'filename' for archive listing 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741280950a2370003.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论