カスタムフィールド youtube プラグイン:Advanced Custom Fields

css

.VideoWrapper {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    padding-top: 25px;
    height: 0;
}
 
.VideoWrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

-----

 

single.php など

-----

<?php if( get_field('youtube_url') ){ ?>
 
<div class="VideoWrapper">
    <?php echo $embed_code = wp_oembed_get( get_field('youtube_url') ); ?>
</div>
 
<?php } ?>
 -