Last active
December 17, 2016 14:01
-
-
Save MatRouault/b325093b1af655ef5a9ff0d674ee9f50 to your computer and use it in GitHub Desktop.
Add a video or featured image above post header
This file contains 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 | |
/*https://community.getbeans.io/discussion/video-post/#post-3032 */ | |
add_action( 'admin_init', 'my_function_name' ); | |
function my_function_name() { | |
$fields = array( | |
array( | |
'id' => 'video_id', | |
'label' => 'The URL of my video', | |
'type' => 'text', | |
'default' => 'https://www.youtube.com/watch?v=gxW3qrU1spI' | |
), | |
); | |
beans_register_post_meta( $fields, array( 'post' ), 'section_id', array( 'title' => 'My video meta box' ) ); | |
} | |
beans_add_smart_action ( 'beans_post_header_before_markup', 'mytheme_video_above_title' ); | |
function mytheme_video_above_title () { | |
if ( is_singular ('post') ) { | |
$videourl = beans_get_post_meta( 'video_id' ); | |
if ( ! empty( $videourl ) ) { | |
echo wp_oembed_get ( $videourl ) ; | |
} | |
elseif ( has_post_thumbnail() ) { | |
echo the_post_thumbnail('large'); | |
} | |
else { | |
echo "something else"; | |
} | |
} | |
} | |
// Load Beans | |
beans_load_document(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment