1

Using WordPress 4.4.2 (latest version as of writing this)

I'm trying to use the [video] shortcode to show a video on my site. If I provide a url ending with the filename.mp4 it works fine:

[video src="http://example.com/filename.mp4"]

but when I add a querystring parameter to the end of the URL, it refuses to show the video player. Instead, it just shows me a link to the URL:

[video src="http://example.com/filename.mp4?type=0"]

I've tried using the mp4 attribute, and it produces the same result.

How do I get the [video] shortcode to allow querystring parameters in the src or mp4 attributes?

2

You got two options.

Either you filter your valid video extentions as @birgire recommended.

I remember a similar issue for the audio shortcode here.

There I found a workaround by allowing the empty audio extension.

You could try something similar with the video extensions. Here's a demo plugin:

/**
 * Allow the empty video extension to support GET parameters
 */
add_filter( 'wp_video_extensions', function( $ext )
{
    $ext[] = '';
    return $ext;
} );

You should then restrict this further as needed, e.g. in a similar way as I did with the audio shortcode.

I searched the trac tickets and found this one #30377 that's being worked on.

Or filter the whole shortcode to your needs with the filter wp_video_shortcode. E.g. add another attribute to the shortcode called type and modify the result to your need.

function my_video_shortcode($output, $atts, $video, $post_id, $library ) {
    /**
     * @param string $output  Video shortcode HTML output.
     * @param array  $atts    Array of video shortcode attributes.
     * @param string $video   Video file.
     * @param int    $post_id Post ID.
     * @param string $library Media library used for the video shortcode.
     */
}

Source: https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes/media.php#L2369

2

I remember a similar issue for the audio shortcode here.

There I found a workaround by allowing the empty audio extension.

You could try something similar with the video extensions. Here's a demo plugin:

<?php
/**
 * Plugin Name:  GET Parameters In The Video Shortcode
 * Description:  Allow video files with GET parameters in the video shortcode [video]
 * Author:       Birgir Erlendsson (birgire)
 * Plugin URI:   https://wordpress.stackexchange.com/a/220573/26350
 * Version:      1.0.0
 */
add_filter( 'wp_video_shortcode_override', function( $html, $atts )
{
    add_filter( 'wp_video_extensions', 'wpse_video_extensions' );
    return $html;
}, 10, 2 );

function wpse_video_extensions( $ext )
{
    remove_filter( current_filter(), __FUNCTION__ );
    $ext[] = '';
    return $ext;
}

You should then restrict this further as needed, e.g. in a similar way as I did with the audio shortcode.

I searched the trac tickets and found this one #30377 that's being worked on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.