This tutorial is for above user. But it will be very helpful for other Genesis folks.
Step 1: Creating a custom field “video_embed_code” using WP’s Native Custom Fields feature. Go to post’s add/edit screen page and scroll down. You will get “Custom Fields” box. if it is not coming then click on “Screen Options” tab at top right side and tick Custom Fields checkbox. It will appear. Now follow the screenshots.
Step 2: Setting the Widget. In this tutorial I am using Genesis Featured Posts Combo. Because this plugin is supporting the hooks and filters. Here is widget settings:
Step 3: Now I added following codes in functions.php file. gfpc_entry_header
is a hook. Using this hook I am showing the video above the title. I set the priority “7”. Because priority “8” is using for post title. get_post_meta() function is retrieving the data of custom field “video_embed_code”.
1 2 3 4 5 6 7 8 9 10 |
add_action( 'gfpc_entry_header', 'gfpc_add_video_above_post_title', 7, 2 ); function gfpc_add_video_above_post_title( $instance, $widget_id ) { global $post; $video = get_post_meta( $post->ID, 'video_embed_code', true ); if ( $video ) { echo $video; } } |
Damien Carbery says
I was thinking about doing something similar but I was planning to take the YouTube url and use the oEmbed support to convert it to be viewable. Could your code be adapted where the ‘video_embed_code’ field only has the url?
Paul says
Thank you for contacting me. I shall test this locally and then confirm you.
Paul says
I just tested the URL option and it is working fine. I tried this simple PHP script for displaying the video.
[code]
add_action( ‘gfpc_entry_header’, ‘gfpc_add_video_above_post_title’, 7, 2 );
function gfpc_add_video_above_post_title( $instance, $widget_id ) {
global $post;
$video = get_post_meta( $post->ID, ‘video_embed_code’, true );
if ( $video ) {
echo wp_oembed_get( $video, array( ‘width’ => 480 ) );
}
}
]