Last active
September 22, 2017 19:11
-
-
Save lepittenger/35b4ae5ba62328dc0f95dc3f0bd33189 to your computer and use it in GitHub Desktop.
Take a link from a video and embed it before the post content with Genesis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add video from a custom field before the post content on single posts. | |
*/ | |
add_action( 'genesis_entry_content','lp_video_before_entry_content_on_singles', 5 ); | |
function lp_video_before_entry_content_on_singles() { | |
if ( is_singular() ) { | |
// get the video from the custom field the standard WordPress way, even if using ACF | |
$video_url = get_post_meta( get_the_ID(), 'video_url', true ); | |
if ( $video_url ) { | |
echo wp_oembed_get( esc_url( $video_url ), array( 'width' => 680 ) ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment