Home › Forums › Front-end Issues › using file field urls in js/jquery › Reply To: using file field urls in js/jquery
I don’t understand why you’re using $()
around the url values returned by ACF
<?php if( get_row_layout() == 'video' ):?>
<?php if( get_sub_field('video_file') ): ?>
<video id="<?php the_sub_field('video_id'); ?>"></video>
<script>
$(document).ready(function(){
var videoFile = $('#<?php the_sub_field('video_id'); ?>');
var videoM = '<?php the_sub_field('video_file_m'); ?>';
var videoD = '<?php the_sub_field('video_file'); ?>';
var WindowWidth = $(window).width();
if (WindowWidth < 640) {
//It is a small screen
videoFile.append("<source src='"+videoM+"' type='video/mp4' >");
} else {
//It is a big screen or desktop
videoFile.append("<source src='"+videoD+"' type='video/mp4' >");
}
});
</script>
<?php endif; ?>
<?php endif; ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.