Get uploaded video URL


I currently have set up a scrolling banner background image on a home page that works nicely. The image is selected in the page settings using fields specified by the custom fields plugin. See custom function code below which is then echoed using echo dn_get_background_image( get_sub_field("header_background_image") );

// Used to print the responsive output for background images        
function dn_get_background_image ( $image_ID ) {
    global $global_bg_counter;

    $final_output = "";

    $final_output .= '<div class="bg-image hidden-sm hidden-xs bg-image-'.$global_bg_counter.'" style="background-image:url('' . wp_get_attachment_image_src( $image_ID, "full" )[0] . '');"></div>';
    $final_output .= '<div class="bg-image hidden-md hidden-lg bg-image-'.$global_bg_counter.'" style="background-image:url('' . wp_get_attachment_image_src( $image_ID, "large" )[0] . '');"></div>';

    return $final_output;

Now, my problem is I’m trying to replicate this but using videos. So far I have the following setup. I have tested this by putting the actual full video path in the src and that works. So I have a feeling the wp_get_attachment_link is not specified properly but I can’t work it out :/ Any help would be greatly appreciated!

Echo function below. "header_background_video" is the custom field name.

echo dn_get_background_video( get_sub_field("header_background_video") );

Function code below:

// Used to display video
function dn_get_background_video ( $attachment_ID ) {

    $final_output = "";

    $final_output .= '<video src="'' . wp_get_attachment_link( $attachment_ID )[0] . ''"></video>';
    return $final_output;
Adam 2 months 0 Answers 19 views 0

Leave an answer