Embed video above the Featured Post Title

tutorials-request

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-1

step-2

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:

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”.

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;
  }
}
Output:
Displaying video above post title.
Displaying video above post title.

Share This Article

Subscribe Membership Plan ($9.99/mo)

  • Get full access to all premium tutorials
  • Get Support for the posted content
  • Request for specific how-to tutorials
  • Cancel the subscription at anytime

Reader Interactions

3 Discussion to This Post

  1. 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?

    • Thank you for contacting me. I shall test this locally and then confirm you.

    • I just tested the URL option and it is working fine. I tried this simple PHP script for displaying the video.

      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 ) );
        }
      }
      

Leave A Reply

Your email address will not be published. Required fields are marked *